diff --git a/app/src/main/java/com/bonus/canteen/activity/InitializationActivity.java b/app/src/main/java/com/bonus/canteen/activity/InitializationActivity.java index cc9e49f..37eb967 100644 --- a/app/src/main/java/com/bonus/canteen/activity/InitializationActivity.java +++ b/app/src/main/java/com/bonus/canteen/activity/InitializationActivity.java @@ -26,7 +26,6 @@ import android.view.LayoutInflater; import android.widget.ListView; import android.widget.TextView; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.arcsoft.face.ErrorInfo; import com.arcsoft.face.FaceEngine; @@ -57,7 +56,6 @@ import com.google.gson.reflect.TypeToken; import com.hjq.permissions.OnPermissionCallback; import com.hjq.permissions.Permission; import com.hjq.permissions.XXPermissions; -import com.umeng.commonsdk.statistics.common.DataHelper; import com.xuexiang.xui.XUI; import com.xuexiang.xui.utils.XToastUtils; @@ -115,26 +113,26 @@ public class InitializationActivity extends BaseActivity { @@ -599,7 +597,8 @@ public class InitializationActivity extends BaseActivity implements BottomNavigationView.OnNavigationItemSelectedListener, ClickUtils.OnClick2ExitListener, Toolbar.OnMenuItemClickListener { +public class OperationActivity extends BaseActivity implements BottomNavigationView.OnNavigationItemSelectedListener, + ClickUtils.OnClick2ExitListener, Toolbar.OnMenuItemClickListener{ private final String TAG = "OperationActivity_log"; @@ -118,10 +129,7 @@ public class OperationActivity extends BaseActivity orderList = new ArrayList<>(); + //获取所有餐单数据 + amount = getOrderData(amount, orderList); + Log.d(TAG, "combineData amount" + amount); + //调用后台支付接口 + try { + JSONObject json = new JSONObject(); + json.put("amount", amount.multiply(BigDecimal.valueOf(100)).longValueExact()); + json.put("consumMode", 1); + json.put("ifOnline", 1); + json.put("macOrderId", macOrderId); + json.put("nuClearMode", nuClearMode); + json.put("orderList", orderList); + json.put("orderType", 11); + json.put("payType", 1); + switch (nuClearMode) { + case 1: + json.put("serialNum", carryGinseng); + break; + case 2: + json.put("openid", carryGinseng); + json.put("custId", "379163979848617984"); + break; + case 3: + json.put("qrCode", carryGinseng); + + json.put("custId", custId); + break; + default: + break; + + } + + String jsonString = json.toString(); + Log.d("combineData jsonString", jsonString); + // 定义 JSON 的 MediaType + MediaType JSON = MediaType.parse("application/json; charset=utf-8"); + // 创建 RequestBody + RequestBody body = RequestBody.create(JSON, jsonString); + String url = WorkConfig.getBaseUrl() + UrlConfig.PLACE_AND_PAY; + Request request = new Request.Builder().url(url) + .addHeader("Authorization", "Bear " + OkHttpService.getToken()) + .addHeader("machine-sn", Objects.requireNonNull(AppUtil.getSn(this))) + .addHeader("machine-num", AppDatabase.getDatabase(this).deviceBaseDao().getDeviceBase().get(0).getDeviceNum()) + .post(body).build(); + + Log.d(TAG, "combineData: " + url); + Log.d(TAG, "combineData:getSn " + Objects.requireNonNull(AppUtil.getSn(this))); + Log.d(TAG, "combineData:getDeviceNum " + AppDatabase.getDatabase(this).deviceBaseDao().getDeviceBase().get(0).getDeviceNum()); + +// String result = service.httpPost(url, body, OperationActivity.this, request); +// Log.i("getPersonMessage result", result); + + } catch (Exception e) { + e.printStackTrace(); + Log.e(TAG, "支付出错:" + e.getMessage()); + XToastUtils.error("支付出错"); } + } - public void openScan(){ + + private BigDecimal getOrderData(BigDecimal amount, List orderList) { + String canteenId = AppDatabase.getDatabase(this).deviceBaseDao().getDeviceBase().get(0).getCanteenId(); + String canteenName = AppDatabase.getDatabase(this).deviceBaseDao().getDeviceBase().get(0).getCanteenName(); + String recipeList = AppDatabase.getDatabase(this).deviceBaseDao().getDeviceBase().get(0).getRecipeList(); + String stallId = ""; + String stallName = ""; + JSONArray jsonArray = JSON.parseArray(recipeList); + if (jsonArray != null) { + stallId = jsonArray.getJSONObject(0).getString("stallId"); + stallName = jsonArray.getJSONObject(0).getString("stallName"); + } + + OrderPayAndroidDTO orderPayAndroidDTO = new OrderPayAndroidDTO(); + orderPayAndroidDTO.setCanteenId(Long.parseLong(canteenId)); + orderPayAndroidDTO.setCanteenName(canteenName); + //配送关联id(位置/取餐柜id) + orderPayAndroidDTO.setDeliveryRelatedId(0L); + //餐次类型(1:早餐 2:午餐 3:下午茶 4:晚餐 5:宵夜) + orderPayAndroidDTO.setMealtimeName("早餐"); + orderPayAndroidDTO.setMealtimeType(1); + orderPayAndroidDTO.setOrderTime(LocalDateTime.now()); + orderPayAndroidDTO.setPlaceId(0); + orderPayAndroidDTO.setStallId(Objects.equals(stallId, "") ? 0 : Long.parseLong(stallId)); + orderPayAndroidDTO.setStallName(stallName); + List orderDetailList = new ArrayList<>(); + for (SalesMenuEntity bean : salesMenuEntityList) { + amount = amount.add(bean.getSubtotal()); + OrderDetailPayDTO orderDetailPayDTO = new OrderDetailPayDTO(); + orderDetailPayDTO.setDetailType(1); + orderDetailPayDTO.setGoodsDishesId(Long.parseLong(bean.getId())); + orderDetailPayDTO.setGoodsDishesName(bean.getName()); + orderDetailPayDTO.setMenuDetailId(Long.parseLong(bean.getId())); + orderDetailPayDTO.setQuantity(bean.getNum().intValue()); + orderDetailPayDTO.setSalePrice(bean.getPrice()); + orderDetailPayDTO.setSalesMode(1); + orderDetailPayDTO.setWeightUnit(100); + orderDetailList.add(orderDetailPayDTO); + } + orderPayAndroidDTO.setOrderDetailList(orderDetailList); + orderList.add(orderPayAndroidDTO); + return amount; + } + + public void openScan() { //开启扫码 - FaceScanUtil.startQrcodeScan(OperationActivity.this, new RecognizeCallback(){ + FaceScanUtil.startQrcodeScan(OperationActivity.this, new RecognizeCallback() { @Override public void onPreView(byte[] data, int width, int height, RectF rect) { Log.e(TAG, "onRecognized: 扫码 onPreView:" + Arrays.toString(data)); @@ -160,9 +282,29 @@ public class OperationActivity extends BaseActivity currentDishList = new ArrayList<>(); String currentTime = DateTimeHelper.getNowTime(); List menuList = jsonObject.getMealList(); - if (jsonObject.getDateList() != null && jsonObject.getDateList().size() > 0 ) { + if (jsonObject.getDateList() != null && jsonObject.getDateList().size() > 0) { Log.d(TAG, "initMenuData getDateList:" + jsonObject.getDateList().toString()); - }else{ + } else { return; } - if(jsonObject.getDateList().get(0).getIntervalList() != null && jsonObject.getDateList().get(0).getIntervalList().size() > 0){ + if (jsonObject.getDateList().get(0).getIntervalList() != null && jsonObject.getDateList().get(0).getIntervalList().size() > 0) { Log.d(TAG, "initMenuData getIntervalList:" + jsonObject.getDateList().get(0).getIntervalList().toString()); - }else{ + } else { return; } //根据当前时间的餐品 for (IssueRecipeIntervalCompressVO vo : jsonObject.getDateList().get(0).getIntervalList()) { if (DateTimeHelper.getDifferTime(currentTime, String.valueOf(vo.getStartTime())) > 0 && DateTimeHelper.getDifferTime(currentTime, String.valueOf(vo.getEndTime())) < 0) { - if (vo.getProductList() != null && vo.getProductList().size() > 0){ + if (vo.getProductList() != null && vo.getProductList().size() > 0) { currentDishList = vo.getProductList(); } break; @@ -370,7 +512,7 @@ public class OperationActivity extends BaseActivity { if (event.getAction() == MotionEvent.ACTION_DOWN) { @@ -471,8 +614,8 @@ public class OperationActivity extends BaseActivity { AlertDialog.Builder builder = new AlertDialog.Builder(OperationActivity.this); View view = LayoutInflater.from(OperationActivity.this).inflate(R.layout.dialog_pick_up_meals, null); - TextView tipTitle= view.findViewById(R.id.tip_title); - TextView pickUpMealsContentTip= view.findViewById(R.id.pick_up_meals_content_tip); + TextView tipTitle = view.findViewById(R.id.tip_title); + TextView pickUpMealsContentTip = view.findViewById(R.id.pick_up_meals_content_tip); TextView close = view.findViewById(R.id.btn_close); builder.setView(view); pickUpYourMealDialog = builder.create(); @@ -483,7 +626,9 @@ public class OperationActivity extends BaseActivity initMenuData(-1L)); + binding.salesRefresh.setOnClickListener(v -> { + initMenuData(-1L); + }); //加载选菜适配器 mSalesMenuAdapter = new SalesMenuAdapter(this, salesMenuEntityList); @@ -502,34 +647,72 @@ public class OperationActivity extends BaseActivity { + SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_0)); + addKeyboardNum("0", false); + }); - binding.keyboardMain.findViewById(R.id.tv_0).setOnClickListener(view -> addKeyboardNum("0", false)); + binding.keyboardMain.findViewById(R.id.tv_1).setOnClickListener(view -> { + SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_1)); + addKeyboardNum("1", false); + }); - binding.keyboardMain.findViewById(R.id.tv_1).setOnClickListener(view -> addKeyboardNum("1", false)); + binding.keyboardMain.findViewById(R.id.tv_2).setOnClickListener(view -> { + SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_2)); + addKeyboardNum("2", false); + }); - binding.keyboardMain.findViewById(R.id.tv_2).setOnClickListener(view -> addKeyboardNum("2", false)); + binding.keyboardMain.findViewById(R.id.tv_3).setOnClickListener(view -> { + SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_3)); + addKeyboardNum("3", false); + }); - binding.keyboardMain.findViewById(R.id.tv_3).setOnClickListener(view -> addKeyboardNum("3", false)); + binding.keyboardMain.findViewById(R.id.tv_4).setOnClickListener(view -> { + SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_4)); + addKeyboardNum("4", false); + }); - binding.keyboardMain.findViewById(R.id.tv_4).setOnClickListener(view -> addKeyboardNum("4", false)); + binding.keyboardMain.findViewById(R.id.tv_5).setOnClickListener(view -> { + SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_5)); + addKeyboardNum("5", false); + }); + binding.keyboardMain.findViewById(R.id.tv_6).setOnClickListener(view -> { + SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_6)); + addKeyboardNum("6", false); + }); - binding.keyboardMain.findViewById(R.id.tv_5).setOnClickListener(view -> addKeyboardNum("5", false)); + binding.keyboardMain.findViewById(R.id.tv_7).setOnClickListener(view -> { + SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_7)); + addKeyboardNum("7", false); + }); - binding.keyboardMain.findViewById(R.id.tv_6).setOnClickListener(view -> addKeyboardNum("6", false)); + binding.keyboardMain.findViewById(R.id.tv_8).setOnClickListener(view -> { + SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_8)); + addKeyboardNum("8", false); + }); - binding.keyboardMain.findViewById(R.id.tv_7).setOnClickListener(view -> addKeyboardNum("7", false)); + binding.keyboardMain.findViewById(R.id.tv_9).setOnClickListener(view -> { + SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_9)); + addKeyboardNum("9", false); + }); - binding.keyboardMain.findViewById(R.id.tv_8).setOnClickListener(view -> addKeyboardNum("8", false)); + binding.keyboardMain.findViewById(R.id.tv_x).setOnClickListener(view -> { + SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_clear)); + addKeyboardNum("x", false); + }); - binding.keyboardMain.findViewById(R.id.tv_9).setOnClickListener(view -> addKeyboardNum("9", false)); + binding.keyboardMain.findViewById(R.id.tv_add).setOnClickListener(view -> { + SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_add)); + addKeyboardNum("0", true); + }); - binding.keyboardMain.findViewById(R.id.tv_x).setOnClickListener(view -> addKeyboardNum("x", false)); - - binding.keyboardMain.findViewById(R.id.tv_add).setOnClickListener(view -> addKeyboardNum("0", true)); - - binding.keyboardMain.findViewById(R.id.tv_point).setOnClickListener(view -> addKeyboardNum(".", false)); + binding.keyboardMain.findViewById(R.id.tv_point).setOnClickListener(view -> { + SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_dot)); + addKeyboardNum(".", false); + }); binding.keyboardMain.findViewById(R.id.tv_clear).setOnClickListener(view -> { + SoundManager.getInstance().play(Sound.createSimpleSound(R.raw.num_clear)); premiumAmount = new StringBuilder(); premiumAmountEdit.setText(""); }); @@ -539,7 +722,7 @@ public class OperationActivity extends BaseActivity 5){ + return; + } // 直接添加数字 premiumAmount.append(currentNum); } @@ -607,6 +793,9 @@ public class OperationActivity extends BaseActivity 5){ + return; + } int lastPlusIndex = premiumAmount.lastIndexOf("+"); String currentNumber = lastPlusIndex == -1 ? premiumAmount.toString() @@ -674,7 +863,7 @@ public class OperationActivity extends BaseActivity orderDetailList; + private LocalDateTime orderTime; + + private Integer placeId; + + public Integer getPlaceId() { + return placeId; + } + + public void setPlaceId(Integer placeId) { + this.placeId = placeId; + } + public Long getCanteenId() { return canteenId; } @@ -75,4 +88,12 @@ public class OrderPayAndroidDTO { public void setOrderDetailList(List orderDetailList) { this.orderDetailList = orderDetailList; } + + public LocalDateTime getOrderTime() { + return orderTime; + } + + public void setOrderTime(LocalDateTime orderTime) { + this.orderTime = orderTime; + } } diff --git a/app/src/main/java/com/bonus/canteen/face/UserFeatureManager.java b/app/src/main/java/com/bonus/canteen/face/UserFeatureManager.java index e4fff83..6e1404a 100644 --- a/app/src/main/java/com/bonus/canteen/face/UserFeatureManager.java +++ b/app/src/main/java/com/bonus/canteen/face/UserFeatureManager.java @@ -6,7 +6,7 @@ import android.content.SharedPreferences; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; import com.bonus.canteen.adapter.menu.utils.StringHelper; -import com.bonus.canteen.face.entity.BasePersonBean; +import com.bonus.canteen.db.entity.base.CustPhotoFulInfo; import java.util.List; @@ -49,19 +49,19 @@ public class UserFeatureManager { * 获取用户状态 * UserLogin */ - public static List getUserFeature(Context context) { + public static List getUserFeature(Context context) { SharedPreferences sp = getShare(context); String data = sp.getString("FEATURE_DATA", ""); if (StringHelper.isEmpty(data)) return null; - return JSON.parseObject(data, new TypeReference>(){}); + return JSON.parseObject(data, new TypeReference>(){}); } /** * SharedPreferences中是否有UserLogin数据 */ public static boolean hasUserFeture(Context context) { - List list = getUserFeature(context); + List list = getUserFeature(context); //有数据 return list != null && list.size() > 0; } diff --git a/app/src/main/java/com/bonus/canteen/face/entity/FaceRegisterInfo.java b/app/src/main/java/com/bonus/canteen/face/entity/FaceRegisterInfo.java index 675d922..1de8780 100644 --- a/app/src/main/java/com/bonus/canteen/face/entity/FaceRegisterInfo.java +++ b/app/src/main/java/com/bonus/canteen/face/entity/FaceRegisterInfo.java @@ -3,77 +3,15 @@ package com.bonus.canteen.face.entity; public class FaceRegisterInfo { private byte[] featureData; private String name; - private String idCard; + private String custId; private String facePath; - private int isTrain; - private int isContract; - private String isToWork; - private String isOffWork; - private String isFurloughPerson; - private String workerType; - public FaceRegisterInfo(byte[] featureData, String name, String idCard, - String facePath, int isTrain, int isContract, - String isToWork, String isOffWork, - String isFurloughPerson, String workerType) { + public FaceRegisterInfo(byte[] featureData, String name, String custId, + String facePath) { this.featureData = featureData; this.name = name; - this.idCard = idCard; + this.custId = custId; this.facePath = facePath; - this.isTrain = isTrain; - this.isContract = isContract; - this.isToWork = isToWork; - this.isOffWork = isOffWork; - this.isFurloughPerson = isFurloughPerson; - this.workerType = workerType; - } - - public String getWorkerType() { - return workerType; - } - - public void setWorkerType(String workerType) { - this.workerType = workerType; - } - - public String getIsFurloughPerson() { - return isFurloughPerson; - } - - public void setIsFurloughPerson(String isFurloughPerson) { - this.isFurloughPerson = isFurloughPerson; - } - - public String getIsToWork() { - return isToWork; - } - - public void setIsToWork(String isToWork) { - this.isToWork = isToWork; - } - - public String getIsOffWork() { - return isOffWork; - } - - public void setIsOffWork(String isOffWork) { - this.isOffWork = isOffWork; - } - - public String getIdCard() { - return idCard; - } - - public void setIdCard(String idCard) { - this.idCard = idCard; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; } public byte[] getFeatureData() { @@ -84,6 +22,22 @@ public class FaceRegisterInfo { this.featureData = featureData; } + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCustId() { + return custId; + } + + public void setCustId(String custId) { + this.custId = custId; + } + public String getFacePath() { return facePath; } @@ -91,20 +45,4 @@ public class FaceRegisterInfo { public void setFacePath(String facePath) { this.facePath = facePath; } - - public int getIsTrain() { - return isTrain; - } - - public void setIsTrain(int isTrain) { - this.isTrain = isTrain; - } - - public int getIsContract() { - return isContract; - } - - public void setIsContract(int isContract) { - this.isContract = isContract; - } } diff --git a/app/src/main/java/com/bonus/canteen/face/util/CompareResult.java b/app/src/main/java/com/bonus/canteen/face/util/CompareResult.java index 4f4be03..f2d0cfb 100644 --- a/app/src/main/java/com/bonus/canteen/face/util/CompareResult.java +++ b/app/src/main/java/com/bonus/canteen/face/util/CompareResult.java @@ -5,77 +5,16 @@ public class CompareResult { private float similar; private int trackId; private String facePath; - private String idCard; - private int isTrain; - private int isContract; - private String isToWork; - private String isOffWork; - private String isFurloughPerson; - private String workerType; + private String custId; public CompareResult(String userName, float similar, String facePath, - String idCard, int isTrain, int isContract, - String isToWork, String isOffWork, - String isFurloughPerson, String workerType) { + String custId) { this.userName = userName; this.similar = similar; this.facePath = facePath; - this.idCard = idCard; - this.isTrain = isTrain; - this.isContract = isContract; - this.isToWork = isToWork; - this.isOffWork = isOffWork; - this.isFurloughPerson = isFurloughPerson; - this.workerType = workerType; + this.custId = custId; } - public String getWorkerType() { - return workerType; - } - - public void setWorkerType(String workerType) { - this.workerType = workerType; - } - - public String getIsFurloughPerson() { - return isFurloughPerson; - } - - public void setIsFurloughPerson(String isFurloughPerson) { - this.isFurloughPerson = isFurloughPerson; - } - - public String getIsToWork() { - return isToWork; - } - - public void setIsToWork(String isToWork) { - this.isToWork = isToWork; - } - - public String getIsOffWork() { - return isOffWork; - } - - public void setIsOffWork(String isOffWork) { - this.isOffWork = isOffWork; - } - - public String getIdCard() { - return idCard; - } - - public void setIdCard(String idCard) { - this.idCard = idCard; - } - - public String getFacePath() { - return facePath; - } - - public void setFacePath(String facePath) { - this.facePath = facePath; - } public String getUserName() { return userName; @@ -101,35 +40,19 @@ public class CompareResult { this.trackId = trackId; } - public int getIsTrain() { - return isTrain; + public String getFacePath() { + return facePath; } - public void setIsTrain(int isTrain) { - this.isTrain = isTrain; + public void setFacePath(String facePath) { + this.facePath = facePath; } - public int getIsContract() { - return isContract; + public String getCustId() { + return custId; } - public void setIsContract(int isContract) { - this.isContract = isContract; - } - - public String toString() { - return "CompareResult{" + - "userName='" + userName + '\'' + - ", similar=" + similar + - ", trackId=" + trackId + - ", facePath='" + facePath + '\'' + - ", idCard='" + idCard + '\'' + - ", isTrain=" + isTrain + - ", isContract=" + isContract + - ", isToWork='" + isToWork + '\'' + - ", isOffWork='" + isOffWork + '\'' + - ", isFurloughPerson='" + isFurloughPerson + '\'' + - ", workerType='" + workerType + '\'' + - '}'; + public void setCustId(String custId) { + this.custId = custId; } } diff --git a/app/src/main/java/com/bonus/canteen/face/util/FaceServer.java b/app/src/main/java/com/bonus/canteen/face/util/FaceServer.java index d1ecaca..3282235 100644 --- a/app/src/main/java/com/bonus/canteen/face/util/FaceServer.java +++ b/app/src/main/java/com/bonus/canteen/face/util/FaceServer.java @@ -18,8 +18,8 @@ import com.arcsoft.imageutil.ArcSoftImageUtilError; import com.arcsoft.imageutil.ArcSoftRotateDegree; import com.bonus.canteen.adapter.menu.utils.StringHelper; import com.bonus.canteen.adapter.menu.utils.WorkConfig; +import com.bonus.canteen.db.entity.base.CustPhotoFulInfo; import com.bonus.canteen.face.UserFeatureManager; -import com.bonus.canteen.face.entity.BasePersonBean; import com.bonus.canteen.face.entity.FaceRegisterInfo; import java.io.File; @@ -119,25 +119,16 @@ public class FaceServer { if(faceRegisterInfoList == null){ faceRegisterInfoList = new ArrayList<>(); } - List list = UserFeatureManager.getUserFeature(context); + List list = UserFeatureManager.getUserFeature(context); if (list != null && list.size() > 0) { - for (BasePersonBean bean : list) { - if(!StringHelper.isEmptyAndNull(bean.getFaceFeature())){ - byte[] feature = Base64.decode(bean.getFaceFeature(), Base64.DEFAULT); - String facePath = WorkConfig.getFileUrl() + bean.getFacePhoto(); - faceRegisterInfoList.add(new FaceRegisterInfo(feature, bean.getName(), bean.getIdNumber(), - facePath, bean.getIsTrain(), bean.getIsContract(), bean.getIsToWork(), - bean.getIsOffWork(), bean.getIsFurloughPerson(), bean.getWorkerType())); + for (CustPhotoFulInfo bean : list) { + if(!StringHelper.isEmptyAndNull(bean.getFeatures())){ + byte[] feature = Base64.decode(bean.getFeatures(), Base64.DEFAULT); + String facePath = WorkConfig.getFileUrl() + bean.getCustPhotoUrl(); + faceRegisterInfoList.add(new FaceRegisterInfo(feature, "", bean.getCustId(), + facePath)); } } - }else{ - faceRegisterInfoList = new ArrayList<>(); - UserFeatureManager.clearUserFeature(context); - String data = "AID6RAAAoEG+CmM9ODxqPNx9NL1Azwc+d7+ZPH3LkDzL7cq9HyNTPc/wjryOtgQ99cjJPVTzjz1JbwQ9Gnq4vU0portpeDS9YBSDvPqY/b34ap89i6HgvQwIiz2urhE+dnnKPeCjt7twJn87IzekPWhENT7xK5M81jnxvJTZXT1Q8rU92dKVPTxOQjyqOLG89VWXvZ+F0r3Xaig++oe8PKQmW7yN4vK81hSKvdpSOD2Jzzi6L2eOvV0xBzzx5ew8+YppvG4YvD1TgLK8OV5SvZEG8LxmkFo9FT++PUYcxbyalwk7tCo2PCVeNj1ohoo7PZ+JPLDa97x8Ly88OFVgvQB/27b8j2g9uhOZPMCs2jz8xrq9EfwHPpWXiTwb4ty9aTCrPeXPBT1yPvy8nqDuPbIfxb1kT+o8XUSnvRaIi73tW6C9xN5hPe3L3bs+FkY9hX7Lvaix3rwA9g493yVBPK6JPbxmOwu9Xan5PFxNiD0iJqA6B3CcvKS1qb2KZcY99az9u6zjcLwDPU28br/QOrVHtLy0vfu8KFj4vK4gQDwSBPY8CqxVPUAzgj1+ECC8KzqNu+P2uDyHF+Y9dZbdPQXdirwmbQ89Rm40PW4wEz0xV8K88GWXvNb9XrzCR7W9bCjsvZRZkj2Mut08jURuPSrLdr0bfzq9mthCPcfcVL1x+a+9QOO1PXvwWby4voO6l76RvdLXiL2k20k927Fbu3RrlT19WEm9Y5reveplsjv3l4c9NkMuPeWygTzotEg9HqZsvUWHA76y7hK8950QvcgSWbxwrqw8coO6PfTbzTyBBg699yObPXToKz6rqrE91DXMvC2uWTwim0k9TTOlPGYou72e6xG+dF/3vAvdpL2e4F+9rMasvY2CmjwrPbw7wpPQPU18CjwpGS87F1fRvLlNlz0ab2w9W2yzPd4nITwzAa+9U2VYPZAFtj0YBbY947nnPTcJjryi1LE9T9cJvZmNpD3xz2o9x+gkvc3uJT0Iya29F79/vIkAyjxSYnw9YiSeO4fmmLxipbo8u7R5vclu4zxl9ZQ8Xy2vOzcbNz3BXg48Oj7wPaDvjbxXxqg7mX3ovVYcX70iqr688sgCPTQ5Aj3/osA9DQwPvXpjOj2iDGo9oc54PagSY70OBha+FZPOvPip3bw9nRe+Do+ePXY2a72PsXo98ZfOu+fTb727Jri9YJQBvZ+NTjygB9K80guHPAisGL5M9gQ9xecXPVEcpL2ghLg8qHlhvREAZ73dONO9IisJPRHqSD1b8VK7h2FSvcqBt7sjGBA9MwQmPGLbCL2BPBo+7pYpPM86JbtVxxO8xGYhvc9lRD3duyO9BVkiOtYCtz177bY8Pc5yvUdmZD0S+ho4"; - byte[] feature = Base64.decode(data, Base64.DEFAULT); - faceRegisterInfoList.add(new FaceRegisterInfo(feature, "张天强", "342221199711168218", - "/lnyst/uploads/2025/03/26/6053d182-fb27-4c1d-98d0-af16d8c7ea22.jpg", 0, 0, "0", - "0", "0", "0")); } } @@ -286,7 +277,7 @@ public class FaceServer { */ public CompareResult getCollectionFaceLib(FaceFeature faceFeature) { if (faceEngine == null || isProcessing || faceFeature == null || faceRegisterInfoList == null || faceRegisterInfoList.size() == 0) { - return new CompareResult("", 0,"","", 0, 0, "0", "0", "0", "0"); + return new CompareResult("", 0,"",""); } FaceFeature tempFaceFeature = new FaceFeature(); FaceSimilar faceSimilar = new FaceSimilar(); @@ -305,13 +296,7 @@ public class FaceServer { if (maxSimilarIndex != -1) { return new CompareResult(faceRegisterInfoList.get(maxSimilarIndex).getName(), maxSimilar,faceRegisterInfoList.get(maxSimilarIndex).getFacePath(), - faceRegisterInfoList.get(maxSimilarIndex).getIdCard(), - faceRegisterInfoList.get(maxSimilarIndex).getIsTrain(), - faceRegisterInfoList.get(maxSimilarIndex).getIsContract(), - faceRegisterInfoList.get(maxSimilarIndex).getIsToWork(), - faceRegisterInfoList.get(maxSimilarIndex).getIsOffWork(), - faceRegisterInfoList.get(maxSimilarIndex).getIsFurloughPerson(), - faceRegisterInfoList.get(maxSimilarIndex).getWorkerType()); + faceRegisterInfoList.get(maxSimilarIndex).getCustId()); } return null; } diff --git a/app/src/main/java/com/bonus/canteen/presentation/MyPresentation.java b/app/src/main/java/com/bonus/canteen/presentation/MyPresentation.java index ecffa09..1c855d8 100644 --- a/app/src/main/java/com/bonus/canteen/presentation/MyPresentation.java +++ b/app/src/main/java/com/bonus/canteen/presentation/MyPresentation.java @@ -27,12 +27,14 @@ import android.os.Build; import android.os.Bundle; import android.util.Log; import android.view.Display; +import android.view.Gravity; import android.view.Surface; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.ListView; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.Nullable; @@ -47,6 +49,7 @@ import com.arcsoft.face.enums.DetectFaceOrientPriority; import com.arcsoft.face.enums.DetectMode; import com.bonus.canteen.adapter.menu.PayMenuAdapter; import com.bonus.canteen.adapter.menu.entity.SalesMenuEntity; +import com.bonus.canteen.db.AppDatabase; import com.bonus.canteen.face.model.DrawInfo; import com.bonus.canteen.face.util.CameraHelper; import com.bonus.canteen.face.util.CameraListener; @@ -886,7 +889,6 @@ public class MyPresentation extends Presentation { 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"); boolean isAdded = false; @@ -919,18 +921,17 @@ public class MyPresentation extends Presentation { compareResult.setTrackId(requestId); compareResultList.add(compareResult); adapter.notifyItemInserted(compareResultList.size() - 1); -// path = saveFacePhoto(nv21Data.clone(),previewSize.width, previewSize.height, faceInfo); -// uploadFace(compareResult); } requestFeatureStatusMap.put(requestId, RequestFeatureStatus.SUCCEED); if (faceHelper != null) { - faceHelper.setName(requestId, "通过:" + compareResult.getUserName()); - Log.d(TAG, requestId + " 通过:" + compareResult.getUserName()); + String name = AppDatabase.getDatabase(context).custInfoDao().getCustInfoByCustId(compareResult.getCustId()).getCustName(); + faceHelper.setName(requestId, "通过:" + name); + Log.d(TAG, requestId + " 通过:" + name); } } else { Log.d(TAG, "compareResult.getSimilar() < SIMILAR_THRESHOLD"); if (faceHelper != null) { - faceHelper.setName(requestId, "未通过:" + "未注册人员"); + faceHelper.setName(requestId, "未通过: 未注册人员"); Log.d(TAG, requestId + " 未通过:" + "未注册人员"); } retryRecognizeDelayed(requestId); @@ -940,7 +941,7 @@ public class MyPresentation extends Presentation { @Override public void onError(Throwable e) { if (faceHelper != null) { - faceHelper.setName(requestId, "未通过:" + "未注册人员"); + faceHelper.setName(requestId, "未通过: 未注册人员"); Log.d(TAG, requestId + " 未通过:" + "未注册人员"); } retryRecognizeDelayed(requestId); @@ -953,5 +954,10 @@ public class MyPresentation extends Presentation { }); } + public void showText(String text) { + Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT); + toast.setGravity(Gravity.CENTER, 0, 0); + toast.show(); + } } diff --git a/app/src/main/java/com/bonus/canteen/utils/sound/Sound.java b/app/src/main/java/com/bonus/canteen/utils/sound/Sound.java new file mode 100644 index 0000000..d4d6e10 --- /dev/null +++ b/app/src/main/java/com/bonus/canteen/utils/sound/Sound.java @@ -0,0 +1,235 @@ +/* + * 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.utils.sound; + +public class Sound { + public static final int SOUND_TYPE_COMPLEX = 1; + + public static final int SOUND_TYPE_SIMPLE = 0; + + Integer boyEWSoundId; + + Integer boyZWSoundId; + + boolean exitSignal = false; + + Integer girlEWSoundId; + + Integer girlZWSoundId; + + boolean playImmediately = false; + + Integer simpleSoundId; + + int soundType = 0; + + public Sound() {} + + private Sound(Builder paramBuilder) { + setExitSignal(paramBuilder.exitSignal); + setSoundType(paramBuilder.soundType); + setPlayImmediately(paramBuilder.playImmediately); + setSimpleSoundId(paramBuilder.simpleSoundId); + setGirlZWSoundId(paramBuilder.girlZWSoundId); + setBoyZWSoundId(paramBuilder.boyZWSoundId); + setGirlEWSoundId(paramBuilder.girlEWSoundId); + setBoyEWSoundId(paramBuilder.boyEWSoundId); + } + + public static Sound createComplexSound(Integer paramInteger1, Integer paramInteger2, Integer paramInteger3, Integer paramInteger4) { + return createComplexSound(paramInteger1, paramInteger2, paramInteger3, paramInteger4, false); + } + + public static Sound createComplexSound(Integer paramInteger1, Integer paramInteger2, Integer paramInteger3, Integer paramInteger4, boolean paramBoolean) { + return (new Builder()).soundType(1).girlZWSoundId(paramInteger1).girlEWSoundId(paramInteger2).boyZWSoundId(paramInteger3).boyEWSoundId(paramInteger4).playImmediately(paramBoolean).build(); + } + + public static Sound createEmptySound() { + return createEmptySound(false); + } + + public static Sound createEmptySound(boolean paramBoolean) { + return (new Builder()).soundType(0).simpleSoundId(null).playImmediately(paramBoolean).build(); + } + + public static Sound createSimpleSound(int paramInt) { + return createSimpleSound(paramInt, false); + } + + public static Sound createSimpleSound(int paramInt, boolean paramBoolean) { + return (new Builder()).soundType(0).simpleSoundId(Integer.valueOf(paramInt)).playImmediately(paramBoolean).build(); + } + + public Integer getBoyEWSoundId() { + return this.boyEWSoundId; + } + + public Integer getBoyZWSoundId() { + return this.boyZWSoundId; + } + + public Integer getGirlEWSoundId() { + return this.girlEWSoundId; + } + + public Integer getGirlZWSoundId() { + return this.girlZWSoundId; + } + + public Integer getSimpleSoundId() { + return this.simpleSoundId; + } + + public Integer getSoundId() { + Integer integer; + if (this.soundType == 1) { + if (SoundManager.GIRL) { + if (SoundManager.ZW) { + integer = this.girlZWSoundId; + } else { + integer = this.girlEWSoundId; + } + } else if (SoundManager.ZW) { + integer = this.boyZWSoundId; + } else { + integer = this.boyEWSoundId; + } + Integer integer1 = integer; + if (integer == null) + integer1 = this.girlZWSoundId; + integer = integer1; + if (integer1 == null) + integer = this.boyZWSoundId; + integer1 = integer; + if (integer == null) + integer1 = this.girlEWSoundId; + integer = integer1; + if (integer1 == null) + integer = this.boyEWSoundId; + } else { + integer = this.simpleSoundId; + } + return integer; + } + + public int getSoundType() { + return this.soundType; + } + + public boolean isExitSignal() { + return this.exitSignal; + } + + public boolean isPlayImmediately() { + return this.playImmediately; + } + + public void setBoyEWSoundId(Integer paramInteger) { + this.boyEWSoundId = paramInteger; + } + + public void setBoyZWSoundId(Integer paramInteger) { + this.boyZWSoundId = paramInteger; + } + + public void setExitSignal(boolean paramBoolean) { + this.exitSignal = paramBoolean; + } + + public void setGirlEWSoundId(Integer paramInteger) { + this.girlEWSoundId = paramInteger; + } + + public void setGirlZWSoundId(Integer paramInteger) { + this.girlZWSoundId = paramInteger; + } + + public void setPlayImmediately(boolean paramBoolean) { + this.playImmediately = paramBoolean; + } + + public void setSimpleSoundId(Integer paramInteger) { + this.simpleSoundId = paramInteger; + } + + public void setSoundType(int paramInt) { + this.soundType = paramInt; + } + + public static final class Builder { + private Integer boyEWSoundId; + + private Integer boyZWSoundId; + + private boolean exitSignal = false; + + private Integer girlEWSoundId; + + private Integer girlZWSoundId; + + private boolean playImmediately = false; + + private Integer simpleSoundId; + + private int soundType; + + public Builder boyEWSoundId(Integer param1Integer) { + this.boyEWSoundId = param1Integer; + return this; + } + + public Builder boyZWSoundId(Integer param1Integer) { + this.boyZWSoundId = param1Integer; + return this; + } + + public Sound build() { + return new Sound(this); + } + + public Builder exitSignal(boolean param1Boolean) { + this.exitSignal = param1Boolean; + return this; + } + + public Builder girlEWSoundId(Integer param1Integer) { + this.girlEWSoundId = param1Integer; + return this; + } + + public Builder girlZWSoundId(Integer param1Integer) { + this.girlZWSoundId = param1Integer; + return this; + } + + public Builder playImmediately(boolean param1Boolean) { + this.playImmediately = param1Boolean; + return this; + } + + public Builder simpleSoundId(Integer param1Integer) { + this.simpleSoundId = param1Integer; + return this; + } + + public Builder soundType(int param1Int) { + this.soundType = param1Int; + return this; + } + } +} diff --git a/app/src/main/java/com/bonus/canteen/utils/sound/SoundManager.java b/app/src/main/java/com/bonus/canteen/utils/sound/SoundManager.java new file mode 100644 index 0000000..35bfea0 --- /dev/null +++ b/app/src/main/java/com/bonus/canteen/utils/sound/SoundManager.java @@ -0,0 +1,298 @@ +/* + * 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.utils.sound; + + +import android.content.Context; +import android.media.MediaPlayer; +import android.os.Build; +import android.util.Log; + +import com.ccb.facedevice.sdk.mainboard.MainboardManage; +import com.ccb.facedevice.sdk.utils.AppUtil; + +import org.easydarwin.easypusher.R; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class SoundManager { + private static final String TAG = "SoundManager"; + public static Sound BEEP = Sound.createSimpleSound(R.raw.beep); + + public static Sound CALL_SUCCESS; + + public static Sound CARD_GUA_SHI = Sound.createComplexSound(Integer.valueOf(R.raw.card_guashi), null, null, null); + + public static Sound CARD_WU_XIAO; + + public static Sound CLEAR; + + public static Sound COLLECT_SUCCESS; + + public static Sound DEVICE_BUSY; + + public static Sound DOT; + + public static Sound ERROR; + + public static Sound ERROR_CRC; + + public static Sound EXCEPTION; + + public static Sound GET_SUCCESS; + + public static volatile boolean GIRL = true; + + public static Sound JIA; + + public static Sound NOT_BIND; + + public static Sound NOT_PAY; + + public static Sound NO_BALANCE; + + public static Sound NO_PAY; + + public static Sound NUM_0; + + public static Sound NUM_1; + + public static Sound NUM_2; + + public static Sound NUM_3; + + public static Sound NUM_4; + + public static Sound NUM_5; + + public static Sound NUM_6; + + public static Sound NUM_7; + + public static Sound NUM_8; + + public static Sound NUM_9; + + public static Sound NUM_ADD; + + public static Sound NUM_CLEAR; + + public static Sound NUM_DOT; + + public static Sound PAY_FAIL; + + public static Sound PAY_FAIL_NO_BALANCE; + + public static Sound PAY_SUCCESS; + + public static Sound PAY_SUCCESS_NEW; + + public static Sound PLEASE_COLLECT; + + public static Sound PLEASE_PAY; + + public static Sound PLEASE_PAY_NEW; + + public static Sound REFUND_FAIL; + + public static Sound REFUND_SUCCESS; + + public static Sound SETTING; + + public static Sound VERIFY_ERROR; + + public static Sound WARN_WARN; + + public static volatile boolean ZW = true; + + private static SoundManager instance; + + private ExecutorService executorService = null; + + private Context mContext = null; + + private SoundThread soundThread = null; + + static { + CALL_SUCCESS = Sound.createComplexSound(Integer.valueOf(R.raw.call_success), null, null, null); + CARD_WU_XIAO = Sound.createComplexSound(Integer.valueOf(R.raw.card_wuxiao), null, null, null); + CLEAR = Sound.createComplexSound(Integer.valueOf(R.raw.clear), null, null, null, true); + COLLECT_SUCCESS = Sound.createComplexSound(Integer.valueOf(R.raw.collect_success), null, null, null); + DOT = Sound.createComplexSound(Integer.valueOf(R.raw.dot), null, null, null); + ERROR = Sound.createComplexSound(Integer.valueOf(R.raw.error), null, null, null); + ERROR_CRC = Sound.createComplexSound(Integer.valueOf(R.raw.error_crc), null, null, null); + EXCEPTION = Sound.createComplexSound(Integer.valueOf(R.raw.exception), null, null, null); + GET_SUCCESS = Sound.createComplexSound(Integer.valueOf(R.raw.get_success), null, null, null); + JIA = Sound.createComplexSound(Integer.valueOf(R.raw.jia), null, null, null); + NO_BALANCE = Sound.createComplexSound(Integer.valueOf(R.raw.no_balance), null, null, null); + NO_PAY = Sound.createComplexSound(Integer.valueOf(R.raw.nopay), null, null, null); + NOT_BIND = Sound.createComplexSound(Integer.valueOf(R.raw.not_bind), null, null, null); + NOT_PAY = Sound.createComplexSound(Integer.valueOf(R.raw.not_pay), null, null, null); + NUM_0 = Sound.createComplexSound(Integer.valueOf(R.raw.num_0), null, null, null, true); + NUM_1 = Sound.createComplexSound(Integer.valueOf(R.raw.num_1), null, null, null, true); + NUM_2 = Sound.createComplexSound(Integer.valueOf(R.raw.num_2), null, null, null, true); + NUM_3 = Sound.createComplexSound(Integer.valueOf(R.raw.num_3), null, null, null, true); + NUM_4 = Sound.createComplexSound(Integer.valueOf(R.raw.num_4), null, null, null, true); + NUM_5 = Sound.createComplexSound(Integer.valueOf(R.raw.num_5), null, null, null, true); + NUM_6 = Sound.createComplexSound(Integer.valueOf(R.raw.num_6), null, null, null, true); + NUM_7 = Sound.createComplexSound(Integer.valueOf(R.raw.num_7), null, null, null, true); + NUM_8 = Sound.createComplexSound(Integer.valueOf(R.raw.num_8), null, null, null, true); + NUM_9 = Sound.createComplexSound(Integer.valueOf(R.raw.num_9), null, null, null, true); + NUM_ADD = Sound.createComplexSound(Integer.valueOf(R.raw.num_add), null, null, null, true); + NUM_CLEAR = Sound.createComplexSound(Integer.valueOf(R.raw.num_clear), null, null, null, true); + NUM_DOT = Sound.createComplexSound(Integer.valueOf(R.raw.num_dot), null, null, null, true); + PAY_FAIL = Sound.createComplexSound(Integer.valueOf(R.raw.pay_fail), null, null, null, true); + PAY_FAIL_NO_BALANCE = Sound.createComplexSound(Integer.valueOf(R.raw.pay_fail_no_balance), null, null, null); + PAY_SUCCESS = Sound.createComplexSound(Integer.valueOf(R.raw.pay_success), null, null, null); + PAY_SUCCESS_NEW = Sound.createComplexSound(Integer.valueOf(R.raw.pay_success_new), null, null, null); + PLEASE_COLLECT = Sound.createComplexSound(Integer.valueOf(R.raw.please_collect), null, null, null); + PLEASE_PAY = Sound.createComplexSound(Integer.valueOf(R.raw.please_pay), null, null, null); + PLEASE_PAY_NEW = Sound.createComplexSound(Integer.valueOf(R.raw.please_pay_new), null, null, null); + SETTING = Sound.createComplexSound(Integer.valueOf(R.raw.setting), null, null, null); + VERIFY_ERROR = Sound.createComplexSound(Integer.valueOf(R.raw.verify_error), null, null, null); + REFUND_SUCCESS = Sound.createComplexSound(Integer.valueOf(R.raw.refund_success), null, null, null); + REFUND_FAIL = Sound.createComplexSound(Integer.valueOf(R.raw.refund_fail), null, null, null); + DEVICE_BUSY = Sound.createComplexSound(Integer.valueOf(R.raw.device_busy), null, null, null); + WARN_WARN = Sound.createSimpleSound(R.raw.warn_warn); + instance = null; + } + + private final Context appContext; + public static synchronized void initialize(Context context) { + if (instance == null) { + instance = new SoundManager(context); + } + } + + public static SoundManager getInstance() { + if (instance == null) { + throw new IllegalStateException("SoundManager not initialized"); + } + return instance; + } + + private SoundManager(Context context) { + this.appContext = getValidContext(context); + this.soundThread = new SoundThread(appContext); + this.soundThread.start(); + this.executorService = Executors.newFixedThreadPool(3); + } + + private Context getValidContext(Context context) { + if (context == null) { + Context appContext = AppUtil.getApplication(); + if (appContext == null) { + throw new IllegalStateException("Invalid application context"); + } + return appContext; + } + return context.getApplicationContext(); + } + + public void play(Sound sound) { + if (sound == null || sound.isExitSignal()) { + return; + } + + if (sound.isPlayImmediately()) { + playImmediately(sound); + } else { + soundThread.play(sound); + } + } + + private void playImmediately(Sound sound) { + if (sound.getSoundId() == null) { + Log.w(TAG, "Attempting to play sound with null ID"); + return; + } + + try { + executorService.submit(() -> playSoundSync(sound)); + } catch (Exception e) { + Log.e(TAG, "Thread pool overloaded, cannot play sound", e); + } + } + + private void playSoundSync(Sound sound) { + MediaPlayer mediaPlayer = null; + try { + mediaPlayer = createMediaPlayer(sound); + if (mediaPlayer == null) return; + + CountDownLatch latch = new CountDownLatch(1); + setupCompletionListener(mediaPlayer, latch); + + mediaPlayer.start(); + latch.await(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } finally { + releaseMediaPlayer(mediaPlayer); + } + } + + private MediaPlayer createMediaPlayer(Sound sound) { + try { + MediaPlayer player = MediaPlayer.create(appContext, sound.getSoundId()); + if (player == null) { + Log.e(TAG, "Failed to create MediaPlayer for sound: " + sound); + return null; + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && MainboardManage.isYs()) { + player.setPlaybackParams( + player.getPlaybackParams().setSpeed(1.0f) + ); + } + return player; + } catch (Exception e) { + Log.e(TAG, "Error creating MediaPlayer", e); + return null; + } + } + + private void setupCompletionListener(MediaPlayer player, CountDownLatch latch) { + player.setOnCompletionListener(mp -> { + releaseMediaPlayer(mp); + latch.countDown(); + }); + } + + public void release() { + soundThread.release(); + executorService.shutdown(); + } + + private static void releaseMediaPlayer(MediaPlayer player) { + if (player != null) { + try { + if (player.isPlaying()) { + player.stop(); + } + player.release(); + } catch (IllegalStateException e) { + Log.w(TAG, "Error releasing MediaPlayer", e); + } + } + } + + +} diff --git a/app/src/main/java/com/bonus/canteen/utils/sound/SoundThread.java b/app/src/main/java/com/bonus/canteen/utils/sound/SoundThread.java new file mode 100644 index 0000000..73a55d1 --- /dev/null +++ b/app/src/main/java/com/bonus/canteen/utils/sound/SoundThread.java @@ -0,0 +1,197 @@ +/* + * 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.utils.sound; + +import android.content.Context; +import android.media.MediaPlayer; +import android.os.Build; +import android.util.Log; + +import com.ccb.facedevice.sdk.mainboard.MainboardManage; + +import java.util.ArrayDeque; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public class SoundThread extends Thread { + private static final String TAG = "SoundThread"; + public static final int MAX_QUEUE_SIZE = 8; + private static final int MIN_PLAY_INTERVAL_MS = 5; + + private final Lock mainLock = new ReentrantLock(); + private final Condition hasSound = mainLock.newCondition(); + + private final Context context; + private final ArrayDeque soundQueue = new ArrayDeque<>(); + private volatile boolean isReleased = false; + private MediaPlayer mediaPlayer; + + public SoundThread(Context context) { + this.context = context.getApplicationContext(); + } + + public void play(Sound sound) { + mainLock.lock(); + try { + if (!isReleased) { + if (soundQueue.size() >= MAX_QUEUE_SIZE) { + soundQueue.poll(); + } + soundQueue.offer(sound); + hasSound.signal(); + } + } finally { + mainLock.unlock(); + } + } + + public void release() { + mainLock.lock(); + try { + isReleased = true; + soundQueue.clear(); + soundQueue.offer(new Sound.Builder().exitSignal(true).build()); + hasSound.signalAll(); + } finally { + mainLock.unlock(); + } + } + + @Override + public void run() { + while (!isInterrupted() && !isReleased) { + try { + final Sound sound = takeNextSound(); + if (sound == null || sound.isExitSignal()) { + break; + } + + playSound(sound); + handlePlayInterval(sound); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + break; + } + } + releaseResources(); + } + + private Sound takeNextSound() throws InterruptedException { + mainLock.lock(); + try { + while (soundQueue.isEmpty() && !isReleased) { + hasSound.await(); + } + return soundQueue.poll(); + } finally { + mainLock.unlock(); + } + } + + private void playSound(Sound sound) { + try { + if (sound.getSoundId() == null) { + Log.w(TAG, "Invalid sound with null soundId"); + return; + } + + releaseMediaPlayer(); // Release previous player + + mediaPlayer = MediaPlayer.create(context, sound.getSoundId()); + if (mediaPlayer == null) { + Log.e(TAG, "Failed to create MediaPlayer"); + return; + } + + setupPlaybackSpeed(); + mediaPlayer.setOnCompletionListener(this::handlePlayCompletion); + mediaPlayer.start(); + } catch (Exception e) { + Log.e(TAG, "Error playing sound", e); + releaseMediaPlayer(); + } + } + + private void setupPlaybackSpeed() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O + && MainboardManage.isYs()) { + try { + float speed = 1.0F; + mediaPlayer.setPlaybackParams( + mediaPlayer.getPlaybackParams().setSpeed(speed) + ); + } catch (Exception e) { + Log.e(TAG, "Error setting playback speed", e); + } + } + } + + private void handlePlayCompletion(MediaPlayer mp) { + releaseMediaPlayer(); + } + + private void handlePlayInterval(Sound sound) { + mainLock.lock(); + try { + int duration = getSafeDuration(sound); + if (duration > 0) { + TimeUnit.MILLISECONDS.sleep(Math.min(MIN_PLAY_INTERVAL_MS, duration)); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } finally { + mainLock.unlock(); + } + } + + private int getSafeDuration(Sound sound) { + try { + return mediaPlayer != null ? mediaPlayer.getDuration() : 0; + } catch (IllegalStateException e) { + return 0; + } + } + + private void releaseResources() { + mainLock.lock(); + try { + releaseMediaPlayer(); + soundQueue.clear(); + isReleased = true; + } finally { + mainLock.unlock(); + } + } + + private void releaseMediaPlayer() { + if (mediaPlayer != null) { + try { + if (mediaPlayer.isPlaying()) { + mediaPlayer.stop(); + } + mediaPlayer.release(); + } catch (IllegalStateException e) { + Log.w(TAG, "Error releasing MediaPlayer", e); + } finally { + mediaPlayer = null; + } + } + } +} diff --git a/app/src/main/java/com/bonus/canteen/utils/sound/SoundUtil.java b/app/src/main/java/com/bonus/canteen/utils/sound/SoundUtil.java new file mode 100644 index 0000000..4bdac15 --- /dev/null +++ b/app/src/main/java/com/bonus/canteen/utils/sound/SoundUtil.java @@ -0,0 +1,79 @@ +/* + * 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.utils.sound; + +public class SoundUtil { + public static Sound CANCEL_PAY; + + public static Sound ERROR; + + public static Sound HAPPY_BIRTHDAY; + + public static Sound NETWORK_ERROR; + + public static Sound NETWORK_NORMAL; + + public static Sound NEW_ORDER; + + public static Sound NOT_PAY; + + public static Sound NUM_0 = Sound.createComplexSound(Integer.valueOf(2131755055), null, null, null, true); + + public static Sound NUM_1 = Sound.createComplexSound(Integer.valueOf(2131755056), null, null, null, true); + + public static Sound NUM_2 = Sound.createComplexSound(Integer.valueOf(2131755057), null, null, null, true); + + public static Sound NUM_3 = Sound.createComplexSound(Integer.valueOf(2131755058), null, null, null, true); + + public static Sound NUM_4 = Sound.createComplexSound(Integer.valueOf(2131755059), null, null, null, true); + + public static Sound NUM_5 = Sound.createComplexSound(Integer.valueOf(2131755060), null, null, null, true); + + public static Sound NUM_6 = Sound.createComplexSound(Integer.valueOf(2131755061), null, null, null, true); + + public static Sound NUM_7 = Sound.createComplexSound(Integer.valueOf(2131755062), null, null, null, true); + + public static Sound NUM_8 = Sound.createComplexSound(Integer.valueOf(2131755063), null, null, null, true); + + public static Sound NUM_9 = Sound.createComplexSound(Integer.valueOf(2131755064), null, null, null, true); + + public static Sound NUM_ADD = Sound.createComplexSound(Integer.valueOf(2131755065), null, null, null, true); + + public static Sound NUM_CLEAR = Sound.createComplexSound(Integer.valueOf(2131755066), null, null, null, true); + + public static Sound NUM_DOT = Sound.createComplexSound(Integer.valueOf(2131755067), null, null, null, true); + + public static Sound PAY_FAIL_NO_BALANCE; + + public static Sound PLEASE_INSERT_CARD; + + public static Sound PLEASE_PAY = Sound.createComplexSound(Integer.valueOf(2131755084), null, null, null); + + static { + CANCEL_PAY = Sound.createComplexSound(Integer.valueOf(2131755017), null, null, null); + ERROR = Sound.createComplexSound(Integer.valueOf(2131755026), null, null, null); + PAY_FAIL_NO_BALANCE = Sound.createComplexSound(Integer.valueOf(2131755073), null, null, null); + NEW_ORDER = Sound.createComplexSound(Integer.valueOf(2131755049), null, null, null, false); + NOT_PAY = Sound.createComplexSound(Integer.valueOf(2131755054), null, null, null); + HAPPY_BIRTHDAY = Sound.createComplexSound(Integer.valueOf(2131755036), null, null, null, true); + NETWORK_NORMAL = Sound.createComplexSound(Integer.valueOf(2131755048), null, null, null); + NETWORK_ERROR = Sound.createComplexSound(Integer.valueOf(2131755047), null, null, null); + PLEASE_INSERT_CARD = Sound.createComplexSound(Integer.valueOf(2131755083), null, null, null); + } + +} diff --git a/app/src/main/res/drawable-xxxhdpi/ic_keybroad_del_2.png b/app/src/main/res/drawable-xxxhdpi/ic_keybroad_del_2.png new file mode 100644 index 0000000..ea4945f Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_keybroad_del_2.png differ diff --git a/app/src/main/res/layout/canteen_keybroad.xml b/app/src/main/res/layout/canteen_keybroad.xml index 86d9df0..9f8c909 100644 --- a/app/src/main/res/layout/canteen_keybroad.xml +++ b/app/src/main/res/layout/canteen_keybroad.xml @@ -1,5 +1,6 @@ @@ -27,14 +28,14 @@ android:background="@drawable/ic_keybroad_del" android:paddingLeft="5dp" android:textColor="@color/app_color_grey" - android:textFontWeight="1000"/> + android:textFontWeight="1000" /> @@ -48,9 +49,9 @@ android:background="@drawable/btn_border_bg" android:gravity="center" android:letterSpacing="0.2" + android:singleLine="false" android:textColor="@color/app_color_grey" android:textFontWeight="1000" - android:singleLine="false" android:textSize="40sp" /> - + android:orientation="horizontal"> + + + + + + + + + + + + + +