开机自启 主副屏订单数据同步 金额同步

This commit is contained in:
jjLv 2025-03-27 10:20:48 +08:00
parent dd9c18ea0b
commit 6c6e69f900
8 changed files with 173 additions and 73 deletions

View File

@ -40,6 +40,7 @@
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<!-- 开机自启的权限-->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.SUBSCRIBED_FEEDS_READ" />
@ -163,6 +164,16 @@
<service android:name="org.eclipse.paho.android.service.MqttService" />
<!-- 开机自启广播-->
<receiver android:name="com.bonus.canteen.receiver.BootReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter android:priority="1005">
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>

View File

@ -159,33 +159,22 @@ public class OperationActivity extends BaseActivity<ActivityCanteenOperationBind
}
private void showPresentation() {
MyLog.i(TAG, "showPresentation 开始");
if (myPresentation != null) {
myPresentation.dismiss();
myPresentation = null;
}
//方式1
MediaRouter mediaRouter = (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE);
MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_AUDIO);
if (route != null) {
MyLog.i(TAG, "route != null");
Display presentationDisplay = route.getPresentationDisplay();
if (presentationDisplay != null) {
MyLog.i(TAG, "presentationDisplay != null");
myPresentation = new MyPresentation(OperationActivity.this, presentationDisplay);
myPresentation.show();
}
} else {
MyLog.i(TAG, "route == null,不支持分屏");
Toast.makeText(OperationActivity.this, "不支持分屏", Toast.LENGTH_SHORT).show();
XToastUtils.toast("不支持分屏");
}
//方式2
/* DisplayManager mDisplayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
Display[] displays = mDisplayManager.getDisplays();
if (displays.length > 1) {
//displays[0] 主屏displays[1] 副屏
myPresentation = new MyPresentation(MainActivity.this, displays[1]);
myPresentation.show();
} else {
Toast.makeText(MainActivity.this, "不支持分屏", Toast.LENGTH_SHORT).show();
}*/
}
private void initViews() {
@ -551,19 +540,24 @@ public class OperationActivity extends BaseActivity<ActivityCanteenOperationBind
} else {
salesDiscountAmountMoney = salesDiscountAmountMoney.add(salesMenuEntity.getOldPrice().subtract(salesMenuEntity.getPrice()));
}
}
if(salesAmountDueMoney.compareTo(BigDecimal.ZERO) < 0){
salesAmountDueMoney = BigDecimal.ZERO;
}
BigDecimal dueMoney = salesAmountDueMoney.subtract(salesDiscountAmountMoney);
if (dueMoney.compareTo(BigDecimal.ZERO) < 0){
dueMoney = BigDecimal.ZERO;
}
binding.salesNumber.setText("总数量:" + salesNumber + "");
binding.salesTotalMoney.setText("总金额:" + salesAmountDueMoney + "");
binding.salesDiscountAmount.setText(String.valueOf(salesDiscountAmountMoney));
binding.salesAmountDue.setText(String.valueOf(salesAmountDueMoney.subtract(salesDiscountAmountMoney)));
binding.salesAmountDue.setText(String.valueOf(dueMoney));
mSalesMenuAdapter.notifyDataSetChanged();
//TODO 往副屏传输数据 更新adapter
Log.d(TAG, "setViewData: " + salesMenuEntityList.size());
Log.d(TAG, "setViewData: " + salesMenuEntityList.toString());
if (myPresentation != null){
runOnUiThread(() -> {
myPresentation.setSalesData(salesMenuEntityList);
});
Log.d(TAG, "setViewData: myPresentation != null");
myPresentation.setSalesData(salesMenuEntityList);
}
}

View File

@ -29,6 +29,7 @@ import com.bonus.canteen.adapter.menu.entity.SalesMenuEntity;
import org.easydarwin.easypusher.R;
import java.util.ArrayList;
import java.util.List;
public class PayMenuAdapter extends BaseAdapter {
@ -82,6 +83,11 @@ public class PayMenuAdapter extends BaseAdapter {
return convertView;
}
public void setData(List<SalesMenuEntity> rawData) {
list = new ArrayList<>(rawData);
notifyDataSetChanged();
}
private class ViewHolder {
TextView tvFoodName;

View File

@ -18,6 +18,7 @@
package com.bonus.canteen.presentation;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Presentation;
import android.content.Context;
import android.graphics.Point;
@ -31,6 +32,7 @@ import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ListView;
import android.widget.TextView;
import androidx.annotation.Nullable;
@ -68,6 +70,7 @@ import com.xuexiang.xui.utils.XToastUtils;
import org.easydarwin.easypusher.R;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
@ -175,9 +178,41 @@ public class MyPresentation extends Presentation {
private CompositeDisposable delayFaceTaskCompositeDisposable = new CompositeDisposable();
private List<CompareResult> compareResultList;
private FaceSearchResultAdapter adapter;
private TextView tvPayNum, tvPayTotalPrice, tvPayDiscount, tvPayTotalPricePay,payTips;
public void setSalesData(List<SalesMenuEntity> rawData) {
salesMenuEntityList = new ArrayList<>(rawData);
menuAdapter.notifyDataSetChanged();
Log.d(TAG, "setViewData: 进入副屏");
this.salesMenuEntityList = rawData;
// 更新列表
if (menuAdapter != null) {
menuAdapter.setData(rawData);
menuAdapter.notifyDataSetChanged();
setMoneyAndNutrition(rawData);
}
}
@SuppressLint("SetTextI18n")
private void setMoneyAndNutrition(List<SalesMenuEntity> rawData) {
BigDecimal money = new BigDecimal(0);
BigDecimal num = new BigDecimal(0);
BigDecimal preferential = new BigDecimal(0);
for (SalesMenuEntity entity : rawData) {
num = num.add(entity.getNum());
money = money.add(entity.getSubtotal());
preferential = preferential.add((entity.getOldPrice().subtract(entity.getPrice())).multiply(entity.getNum()));
}
BigDecimal payMoney = money.subtract(preferential);
if (payMoney.compareTo(BigDecimal.ZERO) < 0){
payMoney = BigDecimal.ZERO;
}
tvPayNum.setText("总数量:" + num + "");
tvPayTotalPrice.setText("合计:" + money + "");
tvPayDiscount.setText("优惠:" + preferential + "");
tvPayTotalPricePay.setText(payMoney + "");
payTips.setText("请支付:" + payMoney + "");
}
public MyPresentation(Context outerContext, Display display) {
@ -192,6 +227,7 @@ public class MyPresentation extends Presentation {
}
}
}
// 获取副屏旋转方向
public int getMyPresentationRotation() {
if (display != null) {
@ -199,6 +235,7 @@ public class MyPresentation extends Presentation {
}
return Surface.ROTATION_0; // 默认值
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -228,12 +265,17 @@ public class MyPresentation extends Presentation {
salesMenuEntityList = new ArrayList<>();
menuAdapter = new PayMenuAdapter(context, salesMenuEntityList);
mListView.setAdapter(menuAdapter);
menuAdapter.notifyDataSetChanged();
compareResultList = new ArrayList<>();
adapter = new FaceSearchResultAdapter(compareResultList, context);
previewView = findViewById(R.id.texture_preview);
faceRectView = findViewById(R.id.face_rect_view);
tvPayNum = findViewById(R.id.tv_pay_num);
tvPayTotalPrice = findViewById(R.id.tv_pay_total_price);
tvPayDiscount = findViewById(R.id.tv_pay_discount);
tvPayTotalPricePay = findViewById(R.id.tv_pay_total_price_pay);
payTips = findViewById(R.id.pay_tips);
}
private void checkPermissions(String[] neededPermissions) {
@ -341,15 +383,15 @@ public class MyPresentation extends Presentation {
Log.i(TAG, "initEngine: flInitCode: " + flInitCode);
if (ftInitCode != ErrorInfo.MOK) {
String error = "初始化失败,错误码为:"+ ftInitCode;
String error = "初始化失败,错误码为:" + ftInitCode;
Log.i(TAG, "initEngine: " + error);
}
if (frInitCode != ErrorInfo.MOK) {
String error = "初始化失败,错误码为:"+ frInitCode;
String error = "初始化失败,错误码为:" + frInitCode;
Log.i(TAG, "initEngine: " + error);
}
if (flInitCode != ErrorInfo.MOK) {
String error = "初始化失败,错误码为:"+ flInitCode;
String error = "初始化失败,错误码为:" + flInitCode;
Log.i(TAG, "initEngine: " + error);
}
}
@ -378,14 +420,14 @@ public class MyPresentation extends Presentation {
if (faceFeature != null) {
Log.i(TAG, "onPreview: fr end = " + System.currentTimeMillis() + " trackId = " + requestId);
Integer liveness = livenessMap.get(requestId);
Log.e(TAG, "liveness " +liveness);
Log.e(TAG, "liveness " + liveness);
if (!livenessDetect) {
//不做活体检测的情况直接搜索
searchFace(nv21Data,faceFeature, requestId,faceInfo);
searchFace(nv21Data, faceFeature, requestId, faceInfo);
Log.i(TAG, "不做活体检测的情况,直接搜索");
} else if (liveness != null && liveness == LivenessInfo.ALIVE) {
//活体检测通过搜索特征
searchFace(nv21Data,faceFeature, requestId,faceInfo);
searchFace(nv21Data, faceFeature, requestId, faceInfo);
Log.i(TAG, "活体检测通过,搜索特征");
} else {
Log.i(TAG, "活体检测未出结果,或者非活体,延迟执行该函数");
@ -406,7 +448,7 @@ public class MyPresentation extends Presentation {
@Override
public void onNext(Long aLong) {
Log.i(TAG, "活体检测未出结果或者非活体延迟执行该函数onNext");
onFaceFeatureInfoGet(nv21Data,faceFeature, requestId, errorCode,faceInfo);
onFaceFeatureInfoGet(nv21Data, faceFeature, requestId, errorCode, faceInfo);
}
@Override
@ -511,8 +553,8 @@ public class MyPresentation extends Presentation {
.trackedFaceCount(ConfigUtil.getTrackedFaceCount(context))
.build();
Log.i(TAG, "onCameraOpened: trackedFaceCount jieshu");
}else{
Log.i(TAG, "onCameraOpened: trackedFaceCount 切换相机的时候可能会导致预览尺寸发生变化" );
} else {
Log.i(TAG, "onCameraOpened: trackedFaceCount 切换相机的时候可能会导致预览尺寸发生变化");
}
}
@ -744,7 +786,6 @@ public class MyPresentation extends Presentation {
}
/**
* 删除已经离开的人脸
*
@ -810,31 +851,31 @@ public class MyPresentation extends Presentation {
@Override
public void onNext(CompareResult compareResult) {
if (compareResult == null || compareResult.getUserName() == null) {
Log.d(TAG,"compareResult == null || compareResult.getUserName() == null");
Log.d(TAG, "compareResult == null || compareResult.getUserName() == null");
requestFeatureStatusMap.put(requestId, RequestFeatureStatus.FAILED);
if(faceHelper != null) {
if (faceHelper != null) {
faceHelper.setName(requestId, "VISITOR " + requestId);
Log.d(TAG,requestId + " VISITOR " + requestId);
Log.d(TAG, requestId + " VISITOR " + requestId);
}
return;
}
Log.e(TAG, "compareResult is not null");
// Log.i(TAG, "onNext: fr search get result = " + System.currentTimeMillis() + " trackId = " + requestId + " similar = " + compareResult.getSimilar());
if (compareResult.getSimilar() > SIMILAR_THRESHOLD) {
Log.d(TAG,"compareResult.getSimilar() > SIMILAR_THRESHOLD");
Log.d(TAG, "compareResult.getSimilar() > SIMILAR_THRESHOLD");
boolean isAdded = false;
if (compareResultList == null) {
Log.d(TAG,"compareResultList == null");
Log.d(TAG, "compareResultList == null");
requestFeatureStatusMap.put(requestId, RequestFeatureStatus.FAILED);
if(faceHelper != null) {
if (faceHelper != null) {
faceHelper.setName(requestId, "VISITOR " + requestId);
Log.d(TAG,requestId + " VISITOR " + requestId);
Log.d(TAG, requestId + " VISITOR " + requestId);
}
return;
}
for (CompareResult compareResult1 : compareResultList) {
if (compareResult1.getTrackId() == requestId) {
Log.d(TAG,"isAdded = true");
Log.d(TAG, "isAdded = true");
isAdded = true;
break;
}
@ -844,7 +885,7 @@ public class MyPresentation extends Presentation {
//对于多人脸搜索假如最大显示数量为 MAX_DETECT_NUM 且有新的人脸进入则以队列的形式移除
if (compareResultList.size() >= MAX_DETECT_NUM) {
Log.i(TAG, "isAdded " + compareResultList.size());
Log.i(TAG, "isAdded compareResultList.size() > MAX_DETECT_NUM" );
Log.i(TAG, "isAdded compareResultList.size() > MAX_DETECT_NUM");
compareResultList.remove(0);
adapter.notifyItemRemoved(0);
}
@ -856,15 +897,15 @@ public class MyPresentation extends Presentation {
// uploadFace(compareResult);
}
requestFeatureStatusMap.put(requestId, RequestFeatureStatus.SUCCEED);
if(faceHelper != null) {
if (faceHelper != null) {
faceHelper.setName(requestId, "通过:" + compareResult.getUserName());
Log.d(TAG, requestId + " 通过:" + compareResult.getUserName() );
Log.d(TAG, requestId + " 通过:" + compareResult.getUserName());
}
} else {
Log.d(TAG,"compareResult.getSimilar() < SIMILAR_THRESHOLD");
if(faceHelper != null) {
Log.d(TAG, "compareResult.getSimilar() < SIMILAR_THRESHOLD");
if (faceHelper != null) {
faceHelper.setName(requestId, "未通过:" + "未注册人员");
Log.d(TAG, requestId + " 未通过:" + "未注册人员" );
Log.d(TAG, requestId + " 未通过:" + "未注册人员");
}
retryRecognizeDelayed(requestId);
}
@ -872,9 +913,9 @@ public class MyPresentation extends Presentation {
@Override
public void onError(Throwable e) {
if(faceHelper != null) {
if (faceHelper != null) {
faceHelper.setName(requestId, "未通过:" + "未注册人员");
Log.d(TAG, requestId + " 未通过:" + "未注册人员" );
Log.d(TAG, requestId + " 未通过:" + "未注册人员");
}
retryRecognizeDelayed(requestId);
}

View File

@ -0,0 +1,44 @@
/*
* 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.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.bonus.canteen.activity.SplashActivity;
import java.util.Objects;
public class BootReceiver extends BroadcastReceiver {
private static final String TAG = "BootReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "广播接受者, action:" + intent.getAction());
if (Objects.equals(intent.getAction(), Intent.ACTION_BOOT_COMPLETED)) {
// 创建启动主界面的Intent
Intent activityIntent = new Intent(context, SplashActivity.class);
activityIntent.setAction(Intent.ACTION_MAIN);
activityIntent.addCategory(Intent.CATEGORY_LAUNCHER);
activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(activityIntent);
}
}
}

View File

@ -82,10 +82,11 @@
android:gravity="center">
<TextView
android:id="@+id/tv_pay_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="总数量:1份"
android:text="总数量:0份"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
@ -103,20 +104,22 @@
android:orientation="vertical">
<TextView
android:id="@+id/tv_pay_total_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="合计8.00元"
android:text="合计8.0元"
android:textColor="@color/white"
android:textSize="14sp" />
<TextView
android:id="@+id/tv_pay_discount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="优惠0.00元"
android:text="优惠0.0元"
android:textColor="@color/white"
android:textSize="14sp" />
</LinearLayout>
@ -140,9 +143,10 @@
android:textSize="14sp" />
<TextView
android:id="@+id/tv_pay_total_price_pay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8.00元"
android:text="0.0元"
android:textColor="@color/white"
android:textSize="25sp" />
</LinearLayout>
@ -329,12 +333,13 @@
android:background="#4DA9A9A9">
<!-- 支付提示 -->
<TextView
android:id="@+id/pay_tips"
android:layout_width="match_parent"
android:layout_height="100dp"
android:elevation="666dp"
android:gravity="center"
android:padding="16dp"
android:text="请支付 8.00 元"
android:text="请支付 0.0 元"
android:textColor="#fff"
android:textSize="28sp"
tools:ignore="MissingConstraints" />

View File

@ -30,15 +30,14 @@
android:textFontWeight="1000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:text="手动输入"
android:textSize="25sp"
android:gravity="center"
android:textColor="@color/black"
android:textFontWeight="1000" />
android:textFontWeight="1000"
android:textSize="25sp" />
</RelativeLayout>
<TextView
@ -56,19 +55,19 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_height="360dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="400dp"
android:layout_height="360dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/tv_7"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@drawable/btn_border_bg"
@ -81,7 +80,7 @@
<TextView
android:id="@+id/tv_4"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@drawable/btn_border_bg"
@ -94,7 +93,7 @@
<TextView
android:id="@+id/tv_1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@drawable/btn_border_bg"
@ -107,7 +106,7 @@
<TextView
android:id="@+id/tv_0"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="@drawable/btn_border_bg"
@ -120,7 +119,7 @@
<LinearLayout
android:layout_width="0dp"
android:layout_height="400dp"
android:layout_height="360dp"
android:layout_weight="1"
android:orientation="vertical">
@ -179,7 +178,7 @@
<LinearLayout
android:layout_width="0dp"
android:layout_height="400dp"
android:layout_height="360dp"
android:layout_weight="1"
android:orientation="vertical">
@ -238,7 +237,7 @@
<LinearLayout
android:layout_width="0dp"
android:layout_height="400dp"
android:layout_height="360dp"
android:layout_weight="1"
android:orientation="vertical">

View File

@ -52,6 +52,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/layout_book_keeping"
@ -82,7 +83,6 @@
android:textColor="@color/white"
android:textSize="25sp"
android:background="@drawable/btn_border_orange_bg"
android:id="@+id/btn_pay_cancel"/>
</LinearLayout>