From 6d17ad72efcafa5e39c7eac8d18498dbf20daa77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Sat, 24 Feb 2024 21:17:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=87=83=E6=B0=94=E7=82=92=E9=94=85UI=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bnframework/Dialog/DialogManager.java | 19 +++-- .../business/ExecuteTheRecipe.java | 74 +++++++++++-------- .../home/fragment/HandControlFragment.java | 12 +-- .../home/fragment/MakeGoodFragment.java | 5 +- app/src/main/res/layout/activity_dialog.xml | 6 -- 5 files changed, 61 insertions(+), 55 deletions(-) diff --git a/app/src/main/java/com/bonait/bnframework/Dialog/DialogManager.java b/app/src/main/java/com/bonait/bnframework/Dialog/DialogManager.java index b10387a8..0994ac66 100644 --- a/app/src/main/java/com/bonait/bnframework/Dialog/DialogManager.java +++ b/app/src/main/java/com/bonait/bnframework/Dialog/DialogManager.java @@ -85,8 +85,11 @@ public class DialogManager { private static Context mContext; - public static void setContext(Context _ct){ - mContext = _ct; + private static Activity mActivity; + + public static void Init(Context context,Activity activity){ + mContext = context; + mActivity=activity; } /** @@ -153,7 +156,9 @@ public class DialogManager { * @param action 执行回调 */ public static void showInfo(String message, AlertDialogButton btn, IDialogAction action) { - showDialog(message,btn,DialogType.提示,action); + if(mActivity!=null) + mActivity.runOnUiThread(()->{showDialog(message,btn,DialogType.提示,action);}); + else showDialog(message,btn,DialogType.提示,action); } /** @@ -163,7 +168,9 @@ public class DialogManager { * @param action 执行回调 */ public static void showWarn(String message, AlertDialogButton btn, IDialogAction action) { - showDialog(message,btn,DialogType.警告,action); + if(mActivity!=null) + mActivity.runOnUiThread(()->{showDialog(message,btn,DialogType.警告,action);}); + else showDialog(message,btn,DialogType.警告,action); } /** @@ -173,7 +180,9 @@ public class DialogManager { * @param action 执行回调 */ public static void showError(String message, AlertDialogButton btn, IDialogAction action) { - showDialog(message,btn,DialogType.错误,action); + if(mActivity!=null) + mActivity.runOnUiThread(()->{showDialog(message,btn,DialogType.错误,action);}); + else showDialog(message,btn,DialogType.错误,action); } } diff --git a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java index ef2cee91..dccf9838 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java +++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java @@ -7,6 +7,7 @@ import android.util.Log; import androidx.annotation.NonNull; +import com.bonait.bnframework.Dialog.DialogManager; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; @@ -184,7 +185,7 @@ public class ExecuteTheRecipe { public static void FaultDetect(){ if(getDeviceData.IgnitionMalfunction.getValue()&&!IsForcedEnd){ MessageLog.ShowError("点火异常中,等待重新点火"); - AlertDialogUtils.showDialog("检测到点火异常,是否复位后重新点火?",AlertDialogButton.YesNo ,(s)->{ + DialogManager.showWarn("检测到点火异常,是否复位后重新点火?",AlertDialogButton.YesNo ,(s)->{ if(s){ BottomClick("点火复位开关");//复位点火开关 } @@ -395,29 +396,34 @@ public class ExecuteTheRecipe { } ExecuteTheRecipe.showlog("工序:手动投料," + name); - String title = "手动投料-温馨提示!"; - String message = "客官请投入主料,[" + name + "],投入后点击[确定]继续流程!"; +// String title = "手动投料-温馨提示!"; +// String message = "客官请投入主料,[" + name + "],投入后点击[确定]继续流程!"; final boolean[] IsComplete = {false}; - Activity activity = findActivity(context); - if (activity != null) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - try { - new QMUIDialog.MessageDialogBuilder(context).setCancelable(false).setCanceledOnTouchOutside(false).setTitle(title).setMessage(message).addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - IsComplete[0] = true; - dialog.dismiss(); - } - }).create(com.qmuiteam.qmui.R.style.QMUI_Dialog).show(); - } catch (Exception e) { - } - } - }); - } + DialogManager.showInfo("请投入主料:[" + name + "]\r\n投入后点击 [确定] 继续流程!", AlertDialogButton.OK,s->{ + IsComplete[0] = s; + }); + +// Activity activity = findActivity(context); +// if (activity != null) { +// activity.runOnUiThread(new Runnable() { +// @Override +// public void run() { +// try { +// new QMUIDialog.MessageDialogBuilder(context).setCancelable(false).setCanceledOnTouchOutside(false).setTitle(title).setMessage(message).addAction("确定", new QMUIDialogAction.ActionListener() { +// @Override +// public void onClick(QMUIDialog dialog, int index) { +// IsComplete[0] = true; +// dialog.dismiss(); +// } +// }).create(com.qmuiteam.qmui.R.style.QMUI_Dialog).show(); +// } catch (Exception e) { +// +// } +// } +// }); +// } while (!IsComplete[0]) { Thread.sleep(100);//10 *6 @@ -532,13 +538,17 @@ public class ExecuteTheRecipe { if(status){ MessageLog.ShowInfo("开火中...."); - //确认点火提示 - mainActivity.runOnUiThread(()->{ - AlertDialogUtils.showDialog(mainContext, "提示", "是否开始点火?",(s)->{ - HeatStatus=s?1:2; - }); + DialogManager.showWarn("点火之前请检查设备是否准备就绪?\r\n是否继续点火?",AlertDialogButton.YesNo,s->{ + HeatStatus=s?1:2; }); + //确认点火提示 +// mainActivity.runOnUiThread(()->{ +// AlertDialogUtils.showDialog(mainContext, "提示", "是否开始点火?",(s)->{ +// HeatStatus=s?1:2; +// }); +// }); + //等待弹框关闭 WaitDialog((s)->{ if(s){ @@ -578,11 +588,13 @@ public class ExecuteTheRecipe { // }); //点火失败提示 - mainActivity.runOnUiThread(()->{ - AlertDialogUtils.showDialog(mainContext, "提示", "点火失败,是否复位后重试?",(s)->{ - HeatStatus=s?1:2; - }); - }); + DialogManager.showError("点火失败,是否复位后重试?",AlertDialogButton.YesNo,s->{HeatStatus=s?1:2; }); + +// mainActivity.runOnUiThread(()->{ +// AlertDialogUtils.showDialog(mainContext, "提示", "点火失败,是否复位后重试?",(s)->{ +// HeatStatus=s?1:2; +// }); +// }); //等待弹框被关闭 WaitDialog((s)->{ diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HandControlFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HandControlFragment.java index 5dd60674..67f478e0 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HandControlFragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HandControlFragment.java @@ -98,7 +98,7 @@ public class HandControlFragment extends BaseFragment { ExecuteTheRecipe.mainContext=context; ExecuteTheRecipe.mainActivity=activity; AlertDialogUtils.getContext=context; - DialogManager.setContext(context); + DialogManager.Init(context,activity); NotifyProp(); Init_弹窗(); StatusOrMakeGoodThread(); @@ -344,15 +344,11 @@ public class HandControlFragment extends BaseFragment { break; case R.id.button_写入参数: - boolean temp = ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.getValue(); - ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.setValue(!temp); - Convert.TryToFloat(edit_温度修正.getText()).OnSource((s)-> { ExecuteTheRecipe.showlog("手动设置温度修正值:"+s.Content); ExecuteTheRecipe.WriteAsync("炒锅温度修正",s.Content); }).OnFailed(f->{ -// AlertDialogUtils.showDialog(context, "提示", "输入的数据格式不匹配,请重试!"); DialogManager.showError("输入的数据格式不匹配,请重试!",AlertDialogButton.OK,null); edit_温度修正.setText("0.0"); }); @@ -361,7 +357,6 @@ public class HandControlFragment extends BaseFragment { ExecuteTheRecipe.showlog("手动设置温度上限值:"+s.Content); ExecuteTheRecipe.WriteAsync("炒锅温度上限设置",s.Content); }).OnFailed(p->{ -// AlertDialogUtils.showDialog(context, "提示", "输入的数据格式不匹配,请重试!"); DialogManager.showError("输入的数据格式不匹配,请重试!",AlertDialogButton.OK,null); edit_温度上限.setText("0.0"); }); @@ -406,7 +401,6 @@ public class HandControlFragment extends BaseFragment { if(!ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.getValue()){ if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){ -// AlertDialogUtils.showDialog("系统未启动,请启动后重试!", AlertDialogButton.OK,(s)->{}); DialogManager.showWarn("系统未启动,请启动后重试!",AlertDialogButton.OK,null); } return false; @@ -587,7 +581,6 @@ public class HandControlFragment extends BaseFragment { private void DeviceControl(boolean isChecked,String name){ if(isChecked&&!ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.getValue()){ -// AlertDialogUtils.showDialog("系统未启动,请启动后重试!", AlertDialogButton.OK,null); DialogManager.showWarn("系统未启动,请启动后重试!",AlertDialogButton.OK,null); } ExecuteTheRecipe.showlog("手动操作-"+name+",值:"+isChecked); @@ -615,7 +608,6 @@ public class HandControlFragment extends BaseFragment { boolean temp=!ExecuteTheRecipe.getDeviceData.StirControlStatusNotify.getValue(); if (temp) { if(!ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.getValue()){ -// AlertDialogUtils.showDialog("系统未启动,请启动后重试!", AlertDialogButton.OK,null); DialogManager.showWarn("系统未启动,请启动后重试!",AlertDialogButton.OK,null); } ExecuteTheRecipe.showlog("手动启动搅拌"); @@ -650,8 +642,6 @@ public class HandControlFragment extends BaseFragment { } - - /** * 初始化弹框中的事件 */ diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java index 38d0da99..65db3a75 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java @@ -168,7 +168,7 @@ public class MakeGoodFragment extends BaseFragment { NotifyProp(); initTopBar(); Initdata(); - DialogManager.setContext(context); + DialogManager.Init(context,activity); CommHelper.get().ConnectOk = new IRun() { @Override public void Run() { @@ -1033,7 +1033,8 @@ public class MakeGoodFragment extends BaseFragment { int ztime = time - ExecuteTheRecipe.HandTime; good.maketime = ztime > 0 ? ztime : time; QueryDB.UpdateGoodsMakeTime(good.id, good.maketime); - getActivity().runOnUiThread(()->{AlertDialogUtils.showDialog(context, "提示", "菜谱【"+good.name+"】:已炒制完成,请出料后再继续!");}); + DialogManager.showInfo("菜谱【"+good.name+"】:已炒制完成,请出料后再继续!",AlertDialogButton.OK,null); +// getActivity().runOnUiThread(()->{AlertDialogUtils.showDialog(context, "提示", "菜谱【"+good.name+"】:已炒制完成,请出料后再继续!");}); } else { ExecuteTheRecipe.showlog("菜谱【" + good.name + "】已强制结束..."); } diff --git a/app/src/main/res/layout/activity_dialog.xml b/app/src/main/res/layout/activity_dialog.xml index c0b9d480..3e5342f3 100644 --- a/app/src/main/res/layout/activity_dialog.xml +++ b/app/src/main/res/layout/activity_dialog.xml @@ -27,12 +27,6 @@ android:text="标题" android:textSize="30sp"/> - - - - - -