From 4fc40b0cc487f3dbddbf373ecf1a34f4662247d0 Mon Sep 17 00:00:00 2001 From: fyf <11621@LAPTOP-04QQU0AO> Date: Mon, 6 Nov 2023 21:33:04 +0800 Subject: [PATCH] 777 --- app/src/main/AndroidManifest.xml | 14 +- .../home/fragment/from/SilosNewActivity.java | 10 +- .../mode/Silos_item_jiaoyan_fragment.java | 131 +-- .../home/fragment/mode/silos_jiaoyan.java | 720 +++++++++++++- .../layout/fragment_silos_item_jiaoyan.xml | 2 +- .../layout/item/layout/silos_jiaoyan_item.xml | 910 +++++++++++++++++- 6 files changed, 1583 insertions(+), 204 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0e18af78..803fea21 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -43,10 +43,7 @@ - + - + - lcModes = new ArrayList<>(); + Activity activity; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_silos_new); - + activity=this; ButterKnife.bind(this); context = getContext(); initTopBar(); @@ -126,7 +128,7 @@ public class SilosNewActivity extends BaseActivity { //设置 } else if (k == 4) { //校准 - silos_jz.SetData((lcMode) data, getSupportFragmentManager()); + silos_jz.SetData((lcMode) data, activity); silos_jz.setVisibility(View.VISIBLE); } else if (k == 5) { // @@ -145,6 +147,7 @@ public class SilosNewActivity extends BaseActivity { @Override public void clickListenerNew(View v, int k, Object data) { if (k == 0) { + InitData(); silos_jz.setVisibility(View.GONE); } } @@ -178,8 +181,6 @@ public class SilosNewActivity extends BaseActivity { List value = map.get(key); LinkMode linkMode = new LinkMode(key.toString(), value, i == 0 ? true : false); Fdata.add(linkMode); - - i++; } @@ -206,6 +207,7 @@ public class SilosNewActivity extends BaseActivity { viewpager_silos.setAdapter(adapter); tabs.setupWithViewPager(viewpager_silos, true); tabs.selectTab(0); + adapter.notifyDataSetChanged(); } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/Silos_item_jiaoyan_fragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/Silos_item_jiaoyan_fragment.java index a2698361..cf172b2e 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/Silos_item_jiaoyan_fragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/Silos_item_jiaoyan_fragment.java @@ -1,10 +1,12 @@ package com.bonait.bnframework.modules.home.fragment.mode; +import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.SystemClock; +import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -40,7 +42,7 @@ import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; -public class Silos_item_jiaoyan_fragment extends BaseFragment { +public class Silos_item_jiaoyan_fragment extends LinearLayout { //region 界面布局 @BindView(R.id.wuliaojiaozhun) @@ -109,7 +111,6 @@ public class Silos_item_jiaoyan_fragment extends BaseFragment { EditText bcjz_clsj; //endregion - //region 变量 private Context context; /** @@ -123,20 +124,12 @@ public class Silos_item_jiaoyan_fragment extends BaseFragment { //endregion //region 界面实例 - @Override - protected View onCreateView() { - - View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_silos_item_jiaoyan, null); + private View root; + public Silos_item_jiaoyan_fragment(Context _context, @Nullable AttributeSet attrs) { + super(_context, attrs); + root= LayoutInflater.from(context).inflate(R.layout.fragment_silos_item_jiaoyan, this); + context=_context; ButterKnife.bind(this, root); - context = getContext(); - return root; - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - Logger.d("我的fragment创建"); - InitView(); } //endregion @@ -188,21 +181,19 @@ public class Silos_item_jiaoyan_fragment extends BaseFragment { }); } - public QMUIFragment SetType(String type) { - TypeName = type; - return this; - } + public Activity activity=null; /** * 设置名称 * * @param */ - public QMUIFragment SetData(lcMode mode) { + public void SetData(String type, lcMode mode, Activity ac) { + TypeName = type; lcMode = mode; - + activity=ac; + InitView(); Run(); - return this; } //endregion @@ -229,29 +220,32 @@ public class Silos_item_jiaoyan_fragment extends BaseFragment { public void Run() { final int kkk = lcMode.num; try { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - try { - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - // 在2秒后执行按钮操作 - int zhongliangxianshi = ExecuteTheRecipe.OutletWeigh; - ExecuteTheRecipe.WritePLC("校准值" + kkk, (short) zhongliangxianshi, null); - String s = String.valueOf(zhongliangxianshi); - String zll = String.format("%.1f", (Double.parseDouble(s) / 10)); - wljz3.setText(zll + ""); - lcMode.jValue = zll; - QueryDB.UpdateJYZ(lcMode.id, zll); - ToastUtils.warning("通道校准完成!"); - } - }, 2000); - } catch (Exception e) { - ToastUtils.error("重量解析显示异常!" + e.getMessage()); + if(activity!=null) + { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + try { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + // 在2秒后执行按钮操作 + int zhongliangxianshi = ExecuteTheRecipe.OutletWeigh; + ExecuteTheRecipe.WritePLC("校准值" + kkk, (short) zhongliangxianshi, null); + String s = String.valueOf(zhongliangxianshi); + String zll = String.format("%.1f", (Double.parseDouble(s) / 10)); + wljz3.setText(zll + ""); + lcMode.jValue = zll; + QueryDB.UpdateJYZ(lcMode.id, zll); + ToastUtils.warning("通道校准完成!"); + } + }, 2000); + } catch (Exception e) { + ToastUtils.error("重量解析显示异常!" + e.getMessage()); + } } - } - }); + }); + } } catch (Exception ex) { Log.d("dsds", "Run: " + ex.getMessage()); } @@ -261,13 +255,10 @@ public class Silos_item_jiaoyan_fragment extends BaseFragment { new Thread(new Runnable() { @Override public void run() { - while (!isAdded()) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - } - } - getActivity().runOnUiThread(new Runnable() { + + if(activity!=null) + { + activity.runOnUiThread(new Runnable() { @Override public void run() { exit_mgjz.setText(lcMode.bValue + ""); @@ -289,6 +280,7 @@ public class Silos_item_jiaoyan_fragment extends BaseFragment { bcjz_gxs.setText(tdclsj); } }); + } } }).start(); @@ -620,12 +612,6 @@ public class Silos_item_jiaoyan_fragment extends BaseFragment { } //endregion - //region 保存校准时间 - public void SaveTime1() { - - } - //endregion - //region 定时器 /** @@ -671,36 +657,5 @@ public class Silos_item_jiaoyan_fragment extends BaseFragment { //endregion //region 关闭窗体事件 - @Override - public void onDestroy() { - super.onDestroy(); - Logger.d("我的fragment销毁"); - - new Thread(new Runnable() { - @Override - public void run() { - try { - ExecuteTheRecipe.WritePLC("通道" + lcMode.num + "校准开关", false, null); - ExecuteTheRecipe.WritePLC("手自切换", true, null); - } catch (Exception e) { - - } - } - }).start(); - } - - /** - * 当在activity设置viewPager + BottomNavigation + fragment时, - * 为防止viewPager左滑动切换界面,与fragment左滑返回上一界面冲突引起闪退问题, - * 必须加上此方法,禁止fragment左滑返回上一界面。 - * - * 切记!切记!切记!否则会闪退! - * - * 当在fragment设置viewPager + BottomNavigation + fragment时,则不会出现这个问题。 - */ - @Override - protected boolean canDragBack() { - return false; - } //endregion } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java index e8e70be2..74ee22e4 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java @@ -1,8 +1,12 @@ package com.bonait.bnframework.modules.home.fragment.mode; +import android.app.Activity; import android.content.Context; import android.content.DialogInterface; +import android.graphics.Color; import android.os.Handler; +import android.os.Message; +import android.os.SystemClock; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; @@ -10,6 +14,7 @@ import android.view.MotionEvent; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.Chronometer; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; @@ -23,10 +28,12 @@ import androidx.fragment.app.FragmentManager; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; +import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.mode.BPA_SILOSANDMATERIAL; import com.bonait.bnframework.common.db.res.lcMode; +import com.bonait.bnframework.common.helper.I.IRun; import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.model.mode.ResMenuLeft; @@ -37,6 +44,7 @@ import com.qmuiteam.qmui.widget.QMUIViewPager; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.tab.QMUIBasicTabSegment; import com.qmuiteam.qmui.widget.tab.QMUITabSegment; +import com.suke.widget.SwitchButton; import java.math.BigDecimal; import java.text.DecimalFormat; @@ -45,18 +53,14 @@ import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.OnClick; public class silos_jiaoyan extends LinearLayout { + //region qita @BindView(R.id.close_from) Button close_from; - @BindView(R.id.tabs_jiaozhun) - QMUITabSegment tabs_jiaozhun; - @BindView(R.id.title_bc) TextView title_bc; - - @BindView(R.id.viewpager_jiaozhun) - QMUIViewPager viewpager_jiaozhun; /** * 当前料仓 */ @@ -65,100 +69,716 @@ public class silos_jiaoyan extends LinearLayout { * 窗体 */ public FragmentManager fragmentManager; - /** - * 空间 - */ - public List froms=new ArrayList<>(); /** * 点击事件 */ public MyClickListener mListener=null; private View root; + //endregion + + //region 界面布局 + @BindView(R.id.wuliaojiaozhun) + LinearLayout wuliaojiaozhun; + @BindView(R.id.manguanjiaozhun) + LinearLayout manguanjiaozhun; + @BindView(R.id.jiaoliaojiaozhun) + LinearLayout jiaoliaojiaozhun; + @BindView(R.id.buchangjiaozhun) + LinearLayout buchangjiaozhun; + //endregion + + //region 称相关 + @BindView(R.id.dianzicheng1) + TextView dianzicheng1; + @BindView(R.id.dianzicheng2) + TextView dianzicheng2; + @BindView(R.id.dianzicheng3) + TextView dianzicheng3; + + @BindView(R.id.chuliaokeshu1) + EditText chuliaokeshu1; + @BindView(R.id.chuliaokeshu2) + EditText chuliaokeshu2; + @BindView(R.id.chuliaokeshu3) + EditText chuliaokeshu3; + //endregion + + //region 满管 + @BindView(R.id.runtime) + Chronometer runtime; + + @BindView(R.id.exit_mgjz) + EditText exit_mgjz; + + final int[] time = {0}; + + final int[] zl = {0}; + //endregion + + //region 物料校准变量 + @BindView(R.id.wljz1) + EditText wljz1; + + @BindView(R.id.wljz2) + EditText wljz2; + + @BindView(R.id.wljz3) + EditText wljz3; + + @BindView(R.id.text_wljz) + TextView text_wljz2; + //endregion + + //region 通道补偿 + @BindView(R.id.control_switch) + SwitchButton control_switch; + + @BindView(R.id.bcjz_gxs) + EditText bcjz_gxs; + + @BindView(R.id.bcjz_dxs) + EditText bcjz_dxs; + + @BindView(R.id.bcjz_clsj) + EditText bcjz_clsj; + //endregion + public silos_jiaoyan(Context context, @Nullable AttributeSet attrs) { super(context, attrs); root= LayoutInflater.from(context).inflate(R.layout.silos_jiaoyan_item, this); ButterKnife.bind(this, root); - Init(); - } - - - public void Init() - { //初始化界面控件的事件 initEvent(); } + @BindView(R.id.text_wlkz) + TextView text_wlkz; + @BindView(R.id.text_mgkz) + TextView text_mgkz; + @BindView(R.id.text_jlkz) + TextView text_jlkz; + @BindView(R.id.text_bckz) + TextView text_bckz; + + @BindView(R.id.text_jlkz1) + TextView text_jlkz1; + @BindView(R.id.text_bckz1) + TextView text_bckz1; /** * 初始化数据 */ private void initData() { title_bc.setText(lcMode.num+" "+lcMode.materialName); - froms.clear(); - Silos_item_jiaoyan_fragment jiaoyan_fragment=new Silos_item_jiaoyan_fragment(); if(lcMode.name.equals("外置仓")) { - froms.add(new ResMenuLeft(new Silos_item_jiaoyan_fragment().SetType("物料校准"),"物料校准",0,0,true)); - froms.add(new ResMenuLeft(new Silos_item_jiaoyan_fragment().SetType("满管校准"),"满管校准",0,0,false)); - froms.add(new ResMenuLeft(new Silos_item_jiaoyan_fragment().SetType("酱料校准"),"酱料校准",0,0,false)); - froms.add(new ResMenuLeft(new Silos_item_jiaoyan_fragment().SetType("补偿校准"),"补偿校准",0,0,false)); }else { - froms.add(new ResMenuLeft(new Silos_item_jiaoyan_fragment().SetType("物料校准"),"物料校准",0,0,true)); - froms.add(new ResMenuLeft(new Silos_item_jiaoyan_fragment().SetType("满管校准"),"满管校准",0,0,false)); + text_jlkz.setVisibility(View.GONE); + text_bckz.setVisibility(View.GONE); + text_jlkz1.setVisibility(View.GONE); + text_bckz1.setVisibility(View.GONE); } + } - QMUIFragmentPagerAdapter adapter = new QMUIFragmentPagerAdapter(fragmentManager) { + private void initEvent() + { + //关闭窗体 + close_from.setOnClickListener(new View.OnClickListener() { @Override - public int getCount() { - return froms.size(); + public void onClick(View v) { + new Thread(new Runnable() { + @Override + public void run() { + try { + ExecuteTheRecipe.WritePLC("通道" + lcMode.num + "校准开关", false, null); + ExecuteTheRecipe.WritePLC("手自切换", true, null); + } catch (Exception e) { + + } + } + }).start(); + if (mListener != null) { + mListener.clickListenerNew(v,0,null); + } } + }); + text_wlkz.setOnClickListener(new View.OnClickListener() { @Override - public QMUIFragment createFragment(int position) { - //显示数元 - return ((Silos_item_jiaoyan_fragment)froms.get(position).fragment).SetData(lcMode); + public void onClick(View v) { + InitView("物料校准"); + } + }); + text_mgkz.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + InitView("满管校准"); + } + }); + text_jlkz.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + InitView("酱料校准"); } + }); + text_bckz.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + InitView("补偿校准"); + } + }); + } + + Activity activity =null; + /** + * 设置数据 + * @param + */ + public void SetData(lcMode _lcMode,Activity ac) + { + activity=ac; + this.lcMode=_lcMode; + initData(); + InitView("物料校准"); + Run(); + } + + //region 初始化设置数据 + public String TypeName="物料校准"; + /** + * 初始化界面 + */ + public void InitView(String _TypeName) { + TypeName=_TypeName; + switch (TypeName) { + case "满管校准": + wuliaojiaozhun.setVisibility(View.GONE); + manguanjiaozhun.setVisibility(View.VISIBLE); + jiaoliaojiaozhun.setVisibility(View.GONE); + buchangjiaozhun.setVisibility(View.GONE); + + text_wlkz.setTextColor(Color.BLACK); + text_mgkz.setTextColor(Color.parseColor("#7dcce1")); + text_jlkz.setTextColor(Color.BLACK); + text_bckz.setTextColor(Color.BLACK); + break; + case "酱料校准": + wuliaojiaozhun.setVisibility(View.GONE); + manguanjiaozhun.setVisibility(View.GONE); + jiaoliaojiaozhun.setVisibility(View.VISIBLE); + buchangjiaozhun.setVisibility(View.GONE); + + text_wlkz.setTextColor(Color.BLACK); + text_mgkz.setTextColor(Color.BLACK); + text_jlkz.setTextColor(Color.parseColor("#7dcce1")); + text_bckz.setTextColor(Color.BLACK); + break; + case "补偿校准": + wuliaojiaozhun.setVisibility(View.GONE); + manguanjiaozhun.setVisibility(View.GONE); + jiaoliaojiaozhun.setVisibility(View.GONE); + buchangjiaozhun.setVisibility(View.VISIBLE); + + text_wlkz.setTextColor(Color.BLACK); + text_mgkz.setTextColor(Color.BLACK); + text_jlkz.setTextColor(Color.BLACK); + text_bckz.setTextColor(Color.parseColor("#7dcce1")); + break; + default: + wuliaojiaozhun.setVisibility(View.VISIBLE); + manguanjiaozhun.setVisibility(View.GONE); + jiaoliaojiaozhun.setVisibility(View.GONE); + buchangjiaozhun.setVisibility(View.GONE); + + text_wlkz.setTextColor(Color.parseColor("#7dcce1")); + text_mgkz.setTextColor(Color.BLACK); + text_jlkz.setTextColor(Color.BLACK); + text_bckz.setTextColor(Color.BLACK); + break; + } + + /** + * 计时器超时 + */ + runtime.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() { @Override - public CharSequence getPageTitle(int position) { - return froms.get(position).name.toString(); + public void onChronometerTick(Chronometer chronometer) { + //如果计时到现在超过了一小时秒 20s + if (SystemClock.elapsedRealtime() - runtime.getBase() > 20 * 1000) { + mHandler.sendEmptyMessage(1); + } } + }); + } + //endregion + //region 外部消息通知 + + /** + * 通知事件 + */ + public void Run() { + //重量通知 + ExecuteTheRecipe.WeighComplete = new IRun() { + @Override + public void Run() { + mHandler.sendEmptyMessage(0); + if (ExecuteTheRecipe.OutletWeigh >= (zl[0] + 2))//当前重量大于2g + { + mHandler.sendEmptyMessage(1); + } + } + }; + //通道校准完成 + ExecuteTheRecipe.OnChargeMixtureComNotPar = new IRun() { @Override - public int getItemPosition(@NonNull Object object) { - return super.getItemPosition(object); + public void Run() { + final int kkk = lcMode.num; + try { + if(activity!=null) + { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + try { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + // 在2秒后执行按钮操作 + int zhongliangxianshi = ExecuteTheRecipe.OutletWeigh; + ExecuteTheRecipe.WritePLC("校准值" + kkk, (short) zhongliangxianshi, null); + String s = String.valueOf(zhongliangxianshi); + String zll = String.format("%.1f", (Double.parseDouble(s) / 10)); + wljz3.setText(zll + ""); + lcMode.jValue = zll; + QueryDB.UpdateJYZ(lcMode.id, zll); + ToastUtils.warning("通道校准完成!"); + } + }, 2000); + } catch (Exception e) { + ToastUtils.error("重量解析显示异常!" + e.getMessage()); + } + } + }); + } + } catch (Exception ex) { + Log.d("dsds", "Run: " + ex.getMessage()); + } } }; - viewpager_jiaozhun.setAdapter(adapter); - tabs_jiaozhun.setupWithViewPager(viewpager_jiaozhun, true); + new Thread(new Runnable() { + @Override + public void run() { + + if(activity!=null) + { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + exit_mgjz.setText(lcMode.bValue + ""); + //填充校准时间 + String time = lcMode.jTime == null ? "0.0" : lcMode.jTime; + String ftime = lcMode.fTime == null ? "0.0" : lcMode.fTime; + String jvalue = lcMode.jValue == null ? "0.0" : lcMode.jValue; + wljz1.setText(time); + wljz2.setText(ftime); + wljz3.setText(jvalue); + + String Gxs = lcMode.Gxs == null ? "0.0" : lcMode.Gxs; + String Lxs = lcMode.Lxs == null ? "0.0" : lcMode.Lxs; + String tdclsj = lcMode.tdclsj == null ? "0.0" : lcMode.tdclsj; + + control_switch.setChecked(lcMode.isOpenbcsf == 1); + bcjz_gxs.setText(Gxs); + bcjz_dxs.setText(Lxs); + bcjz_clsj.setText(tdclsj); + } + }); + } + } + }).start(); } + //endregion - private void initEvent() - { - //关闭窗体 - close_from.setOnClickListener(new View.OnClickListener() { + //region 刷新界面 + /** + * 界面刷新 + */ + private Handler mHandler = new Handler() { + public void handleMessage(Message msg) { + switch (msg.what) { + case 0: + dianzicheng1.setText(String.valueOf((int) ExecuteTheRecipe.OutletWeigh / 10.0) + " g"); + dianzicheng2.setText(String.valueOf((int) ExecuteTheRecipe.OutletWeigh / 10.0) + " g"); + dianzicheng3.setText(String.valueOf((int) ExecuteTheRecipe.OutletWeigh / 10.0) + " g"); + break; + case 1: + time[0] = StopTime(); + lcMode.bValue = time[0]; + exit_mgjz.setText(time[0] + ""); + QueryDB.UpdateMGTime(lcMode.id, time[0]); + break; + case 2: + + break; + } + } + }; + //endregion + + //region 点击事件 + @OnClick({ + R.id.qingling1, R.id.qingling2, R.id.qingling3, + R.id.chuliao1, R.id.chuliao2, R.id.chuliao3, + R.id.click_mgjz, R.id.click_mgjz_save, + R.id.click_wljz, R.id.click_wljz_save, + R.id.control_switch, R.id.click_bcjz_save, + }) + public void onViewClicked(View view) { + switch (view.getId()) { + case R.id.qingling1: + case R.id.qingling2: + case R.id.qingling3: + dzcql(); + break; + case R.id.chuliao1: + case R.id.chuliao2: + case R.id.chuliao3: + mncl(); + break; + case R.id.click_mgjz://满管校准 + zl[0] = ExecuteTheRecipe.OutletWeigh; + StartTime(); + break; + case R.id.click_mgjz_save://满管校准 保存参数 + String value1 = exit_mgjz.getText().toString(); + int val1 = 0; + try { + val1 = (value1 == null || value1.isEmpty()) ? 0 : Integer.parseInt(value1); + lcMode.bValue = val1; + QueryDB.UpdateMGTime(lcMode.id, val1); + ToastUtils.info("校准时间保存成功!"); + } catch (Exception e) { + + } + break; + case R.id.click_wljz://物料校准 + WLJZ(); + break; + case R.id.click_wljz_save://物料校准 保存参数 + SaveWLJZ(); + break; + + case R.id.control_switch://通道开关 + boolean isopen = control_switch.isChecked(); + if (ConfigName.getInstance().PlcIsConnect) { + lcMode.isOpenbcsf=isopen?1:0; + ExecuteTheRecipe.WritePLC("通道" + lcMode.num + "补偿开关", isopen, null); + QueryDB.UpdateSilosisOpenbcsf(lcMode.id, isopen); + ToastUtils.info(lcMode.name.toString() + (isopen ? "打开" : "关闭") + "成功!"); + } else { + ToastUtils.warning(lcMode.name.toString() + (isopen ? "打开" : "关闭") + "失败!PLC未连接!!"); + } + break; + case R.id.click_bcjz_save://补偿校准 保存参数 + SaveBCJZ(); + break; + } + } + //endregion + + //region 电子秤清零 + + /** + * 电子秤清零 + */ + public void dzcql() { + ExecuteTheRecipe.WritePLC("重量清零", true, new IWriteCallBack() { @Override - public void onClick(View v) { - if (mListener != null) { - mListener.clickListenerNew(v,0,null); + public void onSuccess() { + ToastUtils.info("清零成功!"); + } + + @Override + public void onFailure(String ErrorMsg) { + ToastUtils.error("清零失败!"); + } + }); + } + //endregion + + //region 模拟出料 + + /** + * 模拟出料 + */ + public void mncl() { + String zltext = chuliaokeshu1.getText().toString(); + if (TypeName.equals("物料校准")) { + zltext = chuliaokeshu1.getText().toString(); + } else if (TypeName.equals("酱料校准")) { + zltext = chuliaokeshu2.getText().toString(); + } else if (TypeName.equals("补偿校准")) { + zltext = chuliaokeshu3.getText().toString(); + } + + if (zltext.equals("")) { + ToastUtils.warning("出料重量不能为空!"); + return; + } + double zl = 0; + try { + zl = Double.parseDouble(zltext); + } catch (Exception e) { + ToastUtils.warning("出料重量获取异常!" + e.getMessage()); + return; + } + if (zl <= 0) { + ToastUtils.warning("出料重量至少大于0g!"); + return; + } + + if (!ExecuteTheRecipe.IsCup) { + ToastUtils.warning("出料口没有检测到器皿!"); + return; + } + + short kkk = (short) ((int) (zl * 10)); + new Thread(new Runnable() { + @Override + public void run() { + try { + ExecuteTheRecipe.WritePLC("配料完成", false, null); + ExecuteTheRecipe.WritePLC("手自切换", true, null); + ExecuteTheRecipe.WritePLC("需求值" + lcMode.num, kkk, new IWriteCallBack() { + @Override + public void onSuccess() { + ExecuteTheRecipe.WritePLC("配料启动", true, null); + } + + @Override + public void onFailure(String ErrorMsg) { + } + }); + } catch (Exception e) { } } + }).start(); + ToastUtils.info("需求值下发成功!开始配料......"); + } + //endregion + + //region 保存物料校准参数 + public void SaveWLJZ() { + String stime = wljz1.getText().toString(); + String ftime = wljz2.getText().toString(); + String zl = wljz3.getText().toString(); + + if (stime.equals("")) { + ToastUtils.warning("校准基准时间不能为空!"); + return; + } + + if (zl.equals("")) { + ToastUtils.warning("校准重量不能为空!"); + return; + } + + int stime_1 = 0; + int ftime_1 = 0; + + try { + stime_1 = (int) Math.round((Double.parseDouble(stime) * 10)); + } catch (Exception e) { + ToastUtils.error("时间异常!" + e.getMessage()); + return; + } + + try { + Double.parseDouble(zl); + } catch (Exception e) { + ToastUtils.error("重量异常!" + e.getMessage()); + return; + } + if (!ConfigName.getInstance().versionSelectionEnum.equals("奶茶机")) { + if (ftime.equals("")) { + ToastUtils.warning("反转基准时间不能为空!"); + return; + } + try { + ftime_1 = (int) Math.round((Double.parseDouble(ftime) * 10)); + } catch (Exception e) { + ToastUtils.error("时间异常!" + e.getMessage()); + return; + } + ExecuteTheRecipe.WritePLC("反转时间", (short) ftime_1, new IWriteCallBack() { + @Override + public void onSuccess() { + ToastUtils.info("反转时间保存成功!"); + } + + @Override + public void onFailure(String ErrorMsg) { + ToastUtils.error("反转时间保存失败!"); + } + }); + } + lcMode.fTime=ftime; + lcMode.jTime=stime; + lcMode.jValue=zl; + QueryDB.UpdateSilosJZTime(lcMode.id, stime, ftime); + QueryDB.UpdateJYZ(lcMode.id, zl); + ExecuteTheRecipe.WritePLC("基准时间", (short) stime_1, new IWriteCallBack() { + @Override + public void onSuccess() { + ToastUtils.info("校准基准时间保存成功!"); + } + + @Override + public void onFailure(String ErrorMsg) { + ToastUtils.error("校准基准时间保存失败!"); + } }); } + //endregion + + //region 物料校准 + public void WLJZ() { + //判断是否为果糖->判断温度 + if (ConfigName.getInstance().versionSelectionEnum.equals("奶茶机")) { + if (lcMode.num == 11) { + if (ExecuteTheRecipe.SugarTempLeft < ExecuteTheRecipe.SugarTempLeft_SZ) { + ToastUtils.warning("果糖左仓温度未达到设置值,不允许校准..."); + return; + } + } else if (lcMode.num == 12) { + if (ExecuteTheRecipe.SugarTempRight < ExecuteTheRecipe.SugarTempRight_SZ) { + ToastUtils.warning("果糖右仓温度未达到设置值,不允许校准..."); + return; + } + } + } + + new Thread(new Runnable() { + @Override + public void run() { + try { + ExecuteTheRecipe.WritePLC("校准完成", false, null); + ExecuteTheRecipe.WritePLC("手自切换", false, null); + ExecuteTheRecipe.WritePLC("通道校准", true, new IWriteCallBack() { + @Override + public void onSuccess() { + ToastUtils.info("启动通道校准成功!"); + } + + @Override + public void onFailure(String ErrorMsg) { + ToastUtils.error("启动通道校准失败!"); + } + }); + } catch (Exception e) { + } + } + }).start(); + } + //endregion + + //region 补偿校准 + public void SaveBCJZ() { + Short H = 0; + Short L = 0; + Short time = 0; + try { + H = Short.parseShort(bcjz_gxs.getText().toString()); + L = Short.parseShort(bcjz_dxs.getText().toString()); + int ftime = (int) Math.round((Double.parseDouble(bcjz_clsj.getText().toString()) * 10)); + time = (short) ftime; + } catch (Exception ex) { + ToastUtils.error("数据不合法,保存变量失败!" + ex.getMessage()); + return; + } + Short finalH = H; + Short finalL = L; + Short finalTime = time; + + lcMode.Gxs = bcjz_gxs.getText().toString(); + lcMode.Lxs = bcjz_dxs.getText().toString(); + lcMode.tdclsj = bcjz_clsj.getText().toString(); + + new Thread(new Runnable() { + @Override + public void run() { + try { + ExecuteTheRecipe.WritePLC("高系数" + lcMode.num, finalH, null); + ExecuteTheRecipe.WritePLC("低系数" + lcMode.num, finalL, null); + ExecuteTheRecipe.WritePLC("补偿" + lcMode.num + "时间", finalTime, new IWriteCallBack() { + @Override + public void onSuccess() { + ToastUtils.info("保存变量成功!"); + QueryDB.UpdateSilosisOpenbcsf(lcMode.id, bcjz_gxs.getText().toString(), + bcjz_dxs.getText().toString(), bcjz_clsj.getText().toString()); + } + + @Override + public void onFailure(String ErrorMsg) { + ToastUtils.warning("保存变量失败!"); + } + }); + } catch (Exception e) { + + } + } + }).start(); + + } + //endregion + + //region 定时器 /** - * 设置数据 - * @param + * 启动定时器 */ - public void SetData(lcMode _lcMode, FragmentManager _fragmentManager) - { - this.lcMode=_lcMode; - this.fragmentManager=_fragmentManager; + public void StartTime() { + runtime.setBase(SystemClock.elapsedRealtime()); + runtime.start(); + new Thread(new Runnable() { + @Override + public void run() { + try { + //自动模式 + ExecuteTheRecipe.WritePLC("手自切换", false, null); + //开启 + ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, true, null); + } catch (Exception e) { - initData(); + } + } + }).start(); + } + + /** + * 停止定时器 + */ + public int StopTime() { + long elapsedMillis = SystemClock.elapsedRealtime() - runtime.getBase(); + runtime.stop(); + int time = (int) (elapsedMillis / 1000); + new Thread(new Runnable() { + @Override + public void run() { + try { + ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, false, null); + } catch (Exception e) { + + } + } + }).start(); + return time;//当前点击多少秒 } + //endregion } diff --git a/app/src/main/res/layout/item/layout/fragment_silos_item_jiaoyan.xml b/app/src/main/res/layout/item/layout/fragment_silos_item_jiaoyan.xml index db9979e3..6579f95b 100644 --- a/app/src/main/res/layout/item/layout/fragment_silos_item_jiaoyan.xml +++ b/app/src/main/res/layout/item/layout/fragment_silos_item_jiaoyan.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".modules.home.fragment.mode.Silos_item_jiaoyan_fragment"> + > diff --git a/app/src/main/res/layout/item/layout/silos_jiaoyan_item.xml b/app/src/main/res/layout/item/layout/silos_jiaoyan_item.xml index 22e5501e..f05eee30 100644 --- a/app/src/main/res/layout/item/layout/silos_jiaoyan_item.xml +++ b/app/src/main/res/layout/item/layout/silos_jiaoyan_item.xml @@ -14,20 +14,75 @@ android:layout_margin="10dp" android:background="@drawable/common_bg_with_radius_and_border"> - + android:layout_marginTop="15dp" + android:layout_width="wrap_content" + android:layout_height="wrap_content"> + + + + + + + + + + + + + + + - - - - - - - + android:layout_height="match_parent"> + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file
- * 切记!切记!切记!否则会闪退! - *
- * 当在fragment设置viewPager + BottomNavigation + fragment时,则不会出现这个问题。 - */ - @Override - protected boolean canDragBack() { - return false; - } //endregion } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java index e8e70be2..74ee22e4 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java @@ -1,8 +1,12 @@ package com.bonait.bnframework.modules.home.fragment.mode; +import android.app.Activity; import android.content.Context; import android.content.DialogInterface; +import android.graphics.Color; import android.os.Handler; +import android.os.Message; +import android.os.SystemClock; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; @@ -10,6 +14,7 @@ import android.view.MotionEvent; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.Chronometer; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; @@ -23,10 +28,12 @@ import androidx.fragment.app.FragmentManager; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; +import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.mode.BPA_SILOSANDMATERIAL; import com.bonait.bnframework.common.db.res.lcMode; +import com.bonait.bnframework.common.helper.I.IRun; import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.model.mode.ResMenuLeft; @@ -37,6 +44,7 @@ import com.qmuiteam.qmui.widget.QMUIViewPager; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.tab.QMUIBasicTabSegment; import com.qmuiteam.qmui.widget.tab.QMUITabSegment; +import com.suke.widget.SwitchButton; import java.math.BigDecimal; import java.text.DecimalFormat; @@ -45,18 +53,14 @@ import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.OnClick; public class silos_jiaoyan extends LinearLayout { + //region qita @BindView(R.id.close_from) Button close_from; - @BindView(R.id.tabs_jiaozhun) - QMUITabSegment tabs_jiaozhun; - @BindView(R.id.title_bc) TextView title_bc; - - @BindView(R.id.viewpager_jiaozhun) - QMUIViewPager viewpager_jiaozhun; /** * 当前料仓 */ @@ -65,100 +69,716 @@ public class silos_jiaoyan extends LinearLayout { * 窗体 */ public FragmentManager fragmentManager; - /** - * 空间 - */ - public List froms=new ArrayList<>(); /** * 点击事件 */ public MyClickListener mListener=null; private View root; + //endregion + + //region 界面布局 + @BindView(R.id.wuliaojiaozhun) + LinearLayout wuliaojiaozhun; + @BindView(R.id.manguanjiaozhun) + LinearLayout manguanjiaozhun; + @BindView(R.id.jiaoliaojiaozhun) + LinearLayout jiaoliaojiaozhun; + @BindView(R.id.buchangjiaozhun) + LinearLayout buchangjiaozhun; + //endregion + + //region 称相关 + @BindView(R.id.dianzicheng1) + TextView dianzicheng1; + @BindView(R.id.dianzicheng2) + TextView dianzicheng2; + @BindView(R.id.dianzicheng3) + TextView dianzicheng3; + + @BindView(R.id.chuliaokeshu1) + EditText chuliaokeshu1; + @BindView(R.id.chuliaokeshu2) + EditText chuliaokeshu2; + @BindView(R.id.chuliaokeshu3) + EditText chuliaokeshu3; + //endregion + + //region 满管 + @BindView(R.id.runtime) + Chronometer runtime; + + @BindView(R.id.exit_mgjz) + EditText exit_mgjz; + + final int[] time = {0}; + + final int[] zl = {0}; + //endregion + + //region 物料校准变量 + @BindView(R.id.wljz1) + EditText wljz1; + + @BindView(R.id.wljz2) + EditText wljz2; + + @BindView(R.id.wljz3) + EditText wljz3; + + @BindView(R.id.text_wljz) + TextView text_wljz2; + //endregion + + //region 通道补偿 + @BindView(R.id.control_switch) + SwitchButton control_switch; + + @BindView(R.id.bcjz_gxs) + EditText bcjz_gxs; + + @BindView(R.id.bcjz_dxs) + EditText bcjz_dxs; + + @BindView(R.id.bcjz_clsj) + EditText bcjz_clsj; + //endregion + public silos_jiaoyan(Context context, @Nullable AttributeSet attrs) { super(context, attrs); root= LayoutInflater.from(context).inflate(R.layout.silos_jiaoyan_item, this); ButterKnife.bind(this, root); - Init(); - } - - - public void Init() - { //初始化界面控件的事件 initEvent(); } + @BindView(R.id.text_wlkz) + TextView text_wlkz; + @BindView(R.id.text_mgkz) + TextView text_mgkz; + @BindView(R.id.text_jlkz) + TextView text_jlkz; + @BindView(R.id.text_bckz) + TextView text_bckz; + + @BindView(R.id.text_jlkz1) + TextView text_jlkz1; + @BindView(R.id.text_bckz1) + TextView text_bckz1; /** * 初始化数据 */ private void initData() { title_bc.setText(lcMode.num+" "+lcMode.materialName); - froms.clear(); - Silos_item_jiaoyan_fragment jiaoyan_fragment=new Silos_item_jiaoyan_fragment(); if(lcMode.name.equals("外置仓")) { - froms.add(new ResMenuLeft(new Silos_item_jiaoyan_fragment().SetType("物料校准"),"物料校准",0,0,true)); - froms.add(new ResMenuLeft(new Silos_item_jiaoyan_fragment().SetType("满管校准"),"满管校准",0,0,false)); - froms.add(new ResMenuLeft(new Silos_item_jiaoyan_fragment().SetType("酱料校准"),"酱料校准",0,0,false)); - froms.add(new ResMenuLeft(new Silos_item_jiaoyan_fragment().SetType("补偿校准"),"补偿校准",0,0,false)); }else { - froms.add(new ResMenuLeft(new Silos_item_jiaoyan_fragment().SetType("物料校准"),"物料校准",0,0,true)); - froms.add(new ResMenuLeft(new Silos_item_jiaoyan_fragment().SetType("满管校准"),"满管校准",0,0,false)); + text_jlkz.setVisibility(View.GONE); + text_bckz.setVisibility(View.GONE); + text_jlkz1.setVisibility(View.GONE); + text_bckz1.setVisibility(View.GONE); } + } - QMUIFragmentPagerAdapter adapter = new QMUIFragmentPagerAdapter(fragmentManager) { + private void initEvent() + { + //关闭窗体 + close_from.setOnClickListener(new View.OnClickListener() { @Override - public int getCount() { - return froms.size(); + public void onClick(View v) { + new Thread(new Runnable() { + @Override + public void run() { + try { + ExecuteTheRecipe.WritePLC("通道" + lcMode.num + "校准开关", false, null); + ExecuteTheRecipe.WritePLC("手自切换", true, null); + } catch (Exception e) { + + } + } + }).start(); + if (mListener != null) { + mListener.clickListenerNew(v,0,null); + } } + }); + text_wlkz.setOnClickListener(new View.OnClickListener() { @Override - public QMUIFragment createFragment(int position) { - //显示数元 - return ((Silos_item_jiaoyan_fragment)froms.get(position).fragment).SetData(lcMode); + public void onClick(View v) { + InitView("物料校准"); + } + }); + text_mgkz.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + InitView("满管校准"); + } + }); + text_jlkz.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + InitView("酱料校准"); } + }); + text_bckz.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + InitView("补偿校准"); + } + }); + } + + Activity activity =null; + /** + * 设置数据 + * @param + */ + public void SetData(lcMode _lcMode,Activity ac) + { + activity=ac; + this.lcMode=_lcMode; + initData(); + InitView("物料校准"); + Run(); + } + + //region 初始化设置数据 + public String TypeName="物料校准"; + /** + * 初始化界面 + */ + public void InitView(String _TypeName) { + TypeName=_TypeName; + switch (TypeName) { + case "满管校准": + wuliaojiaozhun.setVisibility(View.GONE); + manguanjiaozhun.setVisibility(View.VISIBLE); + jiaoliaojiaozhun.setVisibility(View.GONE); + buchangjiaozhun.setVisibility(View.GONE); + + text_wlkz.setTextColor(Color.BLACK); + text_mgkz.setTextColor(Color.parseColor("#7dcce1")); + text_jlkz.setTextColor(Color.BLACK); + text_bckz.setTextColor(Color.BLACK); + break; + case "酱料校准": + wuliaojiaozhun.setVisibility(View.GONE); + manguanjiaozhun.setVisibility(View.GONE); + jiaoliaojiaozhun.setVisibility(View.VISIBLE); + buchangjiaozhun.setVisibility(View.GONE); + + text_wlkz.setTextColor(Color.BLACK); + text_mgkz.setTextColor(Color.BLACK); + text_jlkz.setTextColor(Color.parseColor("#7dcce1")); + text_bckz.setTextColor(Color.BLACK); + break; + case "补偿校准": + wuliaojiaozhun.setVisibility(View.GONE); + manguanjiaozhun.setVisibility(View.GONE); + jiaoliaojiaozhun.setVisibility(View.GONE); + buchangjiaozhun.setVisibility(View.VISIBLE); + + text_wlkz.setTextColor(Color.BLACK); + text_mgkz.setTextColor(Color.BLACK); + text_jlkz.setTextColor(Color.BLACK); + text_bckz.setTextColor(Color.parseColor("#7dcce1")); + break; + default: + wuliaojiaozhun.setVisibility(View.VISIBLE); + manguanjiaozhun.setVisibility(View.GONE); + jiaoliaojiaozhun.setVisibility(View.GONE); + buchangjiaozhun.setVisibility(View.GONE); + + text_wlkz.setTextColor(Color.parseColor("#7dcce1")); + text_mgkz.setTextColor(Color.BLACK); + text_jlkz.setTextColor(Color.BLACK); + text_bckz.setTextColor(Color.BLACK); + break; + } + + /** + * 计时器超时 + */ + runtime.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() { @Override - public CharSequence getPageTitle(int position) { - return froms.get(position).name.toString(); + public void onChronometerTick(Chronometer chronometer) { + //如果计时到现在超过了一小时秒 20s + if (SystemClock.elapsedRealtime() - runtime.getBase() > 20 * 1000) { + mHandler.sendEmptyMessage(1); + } } + }); + } + //endregion + //region 外部消息通知 + + /** + * 通知事件 + */ + public void Run() { + //重量通知 + ExecuteTheRecipe.WeighComplete = new IRun() { + @Override + public void Run() { + mHandler.sendEmptyMessage(0); + if (ExecuteTheRecipe.OutletWeigh >= (zl[0] + 2))//当前重量大于2g + { + mHandler.sendEmptyMessage(1); + } + } + }; + //通道校准完成 + ExecuteTheRecipe.OnChargeMixtureComNotPar = new IRun() { @Override - public int getItemPosition(@NonNull Object object) { - return super.getItemPosition(object); + public void Run() { + final int kkk = lcMode.num; + try { + if(activity!=null) + { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + try { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + // 在2秒后执行按钮操作 + int zhongliangxianshi = ExecuteTheRecipe.OutletWeigh; + ExecuteTheRecipe.WritePLC("校准值" + kkk, (short) zhongliangxianshi, null); + String s = String.valueOf(zhongliangxianshi); + String zll = String.format("%.1f", (Double.parseDouble(s) / 10)); + wljz3.setText(zll + ""); + lcMode.jValue = zll; + QueryDB.UpdateJYZ(lcMode.id, zll); + ToastUtils.warning("通道校准完成!"); + } + }, 2000); + } catch (Exception e) { + ToastUtils.error("重量解析显示异常!" + e.getMessage()); + } + } + }); + } + } catch (Exception ex) { + Log.d("dsds", "Run: " + ex.getMessage()); + } } }; - viewpager_jiaozhun.setAdapter(adapter); - tabs_jiaozhun.setupWithViewPager(viewpager_jiaozhun, true); + new Thread(new Runnable() { + @Override + public void run() { + + if(activity!=null) + { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + exit_mgjz.setText(lcMode.bValue + ""); + //填充校准时间 + String time = lcMode.jTime == null ? "0.0" : lcMode.jTime; + String ftime = lcMode.fTime == null ? "0.0" : lcMode.fTime; + String jvalue = lcMode.jValue == null ? "0.0" : lcMode.jValue; + wljz1.setText(time); + wljz2.setText(ftime); + wljz3.setText(jvalue); + + String Gxs = lcMode.Gxs == null ? "0.0" : lcMode.Gxs; + String Lxs = lcMode.Lxs == null ? "0.0" : lcMode.Lxs; + String tdclsj = lcMode.tdclsj == null ? "0.0" : lcMode.tdclsj; + + control_switch.setChecked(lcMode.isOpenbcsf == 1); + bcjz_gxs.setText(Gxs); + bcjz_dxs.setText(Lxs); + bcjz_clsj.setText(tdclsj); + } + }); + } + } + }).start(); } + //endregion - private void initEvent() - { - //关闭窗体 - close_from.setOnClickListener(new View.OnClickListener() { + //region 刷新界面 + /** + * 界面刷新 + */ + private Handler mHandler = new Handler() { + public void handleMessage(Message msg) { + switch (msg.what) { + case 0: + dianzicheng1.setText(String.valueOf((int) ExecuteTheRecipe.OutletWeigh / 10.0) + " g"); + dianzicheng2.setText(String.valueOf((int) ExecuteTheRecipe.OutletWeigh / 10.0) + " g"); + dianzicheng3.setText(String.valueOf((int) ExecuteTheRecipe.OutletWeigh / 10.0) + " g"); + break; + case 1: + time[0] = StopTime(); + lcMode.bValue = time[0]; + exit_mgjz.setText(time[0] + ""); + QueryDB.UpdateMGTime(lcMode.id, time[0]); + break; + case 2: + + break; + } + } + }; + //endregion + + //region 点击事件 + @OnClick({ + R.id.qingling1, R.id.qingling2, R.id.qingling3, + R.id.chuliao1, R.id.chuliao2, R.id.chuliao3, + R.id.click_mgjz, R.id.click_mgjz_save, + R.id.click_wljz, R.id.click_wljz_save, + R.id.control_switch, R.id.click_bcjz_save, + }) + public void onViewClicked(View view) { + switch (view.getId()) { + case R.id.qingling1: + case R.id.qingling2: + case R.id.qingling3: + dzcql(); + break; + case R.id.chuliao1: + case R.id.chuliao2: + case R.id.chuliao3: + mncl(); + break; + case R.id.click_mgjz://满管校准 + zl[0] = ExecuteTheRecipe.OutletWeigh; + StartTime(); + break; + case R.id.click_mgjz_save://满管校准 保存参数 + String value1 = exit_mgjz.getText().toString(); + int val1 = 0; + try { + val1 = (value1 == null || value1.isEmpty()) ? 0 : Integer.parseInt(value1); + lcMode.bValue = val1; + QueryDB.UpdateMGTime(lcMode.id, val1); + ToastUtils.info("校准时间保存成功!"); + } catch (Exception e) { + + } + break; + case R.id.click_wljz://物料校准 + WLJZ(); + break; + case R.id.click_wljz_save://物料校准 保存参数 + SaveWLJZ(); + break; + + case R.id.control_switch://通道开关 + boolean isopen = control_switch.isChecked(); + if (ConfigName.getInstance().PlcIsConnect) { + lcMode.isOpenbcsf=isopen?1:0; + ExecuteTheRecipe.WritePLC("通道" + lcMode.num + "补偿开关", isopen, null); + QueryDB.UpdateSilosisOpenbcsf(lcMode.id, isopen); + ToastUtils.info(lcMode.name.toString() + (isopen ? "打开" : "关闭") + "成功!"); + } else { + ToastUtils.warning(lcMode.name.toString() + (isopen ? "打开" : "关闭") + "失败!PLC未连接!!"); + } + break; + case R.id.click_bcjz_save://补偿校准 保存参数 + SaveBCJZ(); + break; + } + } + //endregion + + //region 电子秤清零 + + /** + * 电子秤清零 + */ + public void dzcql() { + ExecuteTheRecipe.WritePLC("重量清零", true, new IWriteCallBack() { @Override - public void onClick(View v) { - if (mListener != null) { - mListener.clickListenerNew(v,0,null); + public void onSuccess() { + ToastUtils.info("清零成功!"); + } + + @Override + public void onFailure(String ErrorMsg) { + ToastUtils.error("清零失败!"); + } + }); + } + //endregion + + //region 模拟出料 + + /** + * 模拟出料 + */ + public void mncl() { + String zltext = chuliaokeshu1.getText().toString(); + if (TypeName.equals("物料校准")) { + zltext = chuliaokeshu1.getText().toString(); + } else if (TypeName.equals("酱料校准")) { + zltext = chuliaokeshu2.getText().toString(); + } else if (TypeName.equals("补偿校准")) { + zltext = chuliaokeshu3.getText().toString(); + } + + if (zltext.equals("")) { + ToastUtils.warning("出料重量不能为空!"); + return; + } + double zl = 0; + try { + zl = Double.parseDouble(zltext); + } catch (Exception e) { + ToastUtils.warning("出料重量获取异常!" + e.getMessage()); + return; + } + if (zl <= 0) { + ToastUtils.warning("出料重量至少大于0g!"); + return; + } + + if (!ExecuteTheRecipe.IsCup) { + ToastUtils.warning("出料口没有检测到器皿!"); + return; + } + + short kkk = (short) ((int) (zl * 10)); + new Thread(new Runnable() { + @Override + public void run() { + try { + ExecuteTheRecipe.WritePLC("配料完成", false, null); + ExecuteTheRecipe.WritePLC("手自切换", true, null); + ExecuteTheRecipe.WritePLC("需求值" + lcMode.num, kkk, new IWriteCallBack() { + @Override + public void onSuccess() { + ExecuteTheRecipe.WritePLC("配料启动", true, null); + } + + @Override + public void onFailure(String ErrorMsg) { + } + }); + } catch (Exception e) { } } + }).start(); + ToastUtils.info("需求值下发成功!开始配料......"); + } + //endregion + + //region 保存物料校准参数 + public void SaveWLJZ() { + String stime = wljz1.getText().toString(); + String ftime = wljz2.getText().toString(); + String zl = wljz3.getText().toString(); + + if (stime.equals("")) { + ToastUtils.warning("校准基准时间不能为空!"); + return; + } + + if (zl.equals("")) { + ToastUtils.warning("校准重量不能为空!"); + return; + } + + int stime_1 = 0; + int ftime_1 = 0; + + try { + stime_1 = (int) Math.round((Double.parseDouble(stime) * 10)); + } catch (Exception e) { + ToastUtils.error("时间异常!" + e.getMessage()); + return; + } + + try { + Double.parseDouble(zl); + } catch (Exception e) { + ToastUtils.error("重量异常!" + e.getMessage()); + return; + } + if (!ConfigName.getInstance().versionSelectionEnum.equals("奶茶机")) { + if (ftime.equals("")) { + ToastUtils.warning("反转基准时间不能为空!"); + return; + } + try { + ftime_1 = (int) Math.round((Double.parseDouble(ftime) * 10)); + } catch (Exception e) { + ToastUtils.error("时间异常!" + e.getMessage()); + return; + } + ExecuteTheRecipe.WritePLC("反转时间", (short) ftime_1, new IWriteCallBack() { + @Override + public void onSuccess() { + ToastUtils.info("反转时间保存成功!"); + } + + @Override + public void onFailure(String ErrorMsg) { + ToastUtils.error("反转时间保存失败!"); + } + }); + } + lcMode.fTime=ftime; + lcMode.jTime=stime; + lcMode.jValue=zl; + QueryDB.UpdateSilosJZTime(lcMode.id, stime, ftime); + QueryDB.UpdateJYZ(lcMode.id, zl); + ExecuteTheRecipe.WritePLC("基准时间", (short) stime_1, new IWriteCallBack() { + @Override + public void onSuccess() { + ToastUtils.info("校准基准时间保存成功!"); + } + + @Override + public void onFailure(String ErrorMsg) { + ToastUtils.error("校准基准时间保存失败!"); + } }); } + //endregion + + //region 物料校准 + public void WLJZ() { + //判断是否为果糖->判断温度 + if (ConfigName.getInstance().versionSelectionEnum.equals("奶茶机")) { + if (lcMode.num == 11) { + if (ExecuteTheRecipe.SugarTempLeft < ExecuteTheRecipe.SugarTempLeft_SZ) { + ToastUtils.warning("果糖左仓温度未达到设置值,不允许校准..."); + return; + } + } else if (lcMode.num == 12) { + if (ExecuteTheRecipe.SugarTempRight < ExecuteTheRecipe.SugarTempRight_SZ) { + ToastUtils.warning("果糖右仓温度未达到设置值,不允许校准..."); + return; + } + } + } + + new Thread(new Runnable() { + @Override + public void run() { + try { + ExecuteTheRecipe.WritePLC("校准完成", false, null); + ExecuteTheRecipe.WritePLC("手自切换", false, null); + ExecuteTheRecipe.WritePLC("通道校准", true, new IWriteCallBack() { + @Override + public void onSuccess() { + ToastUtils.info("启动通道校准成功!"); + } + + @Override + public void onFailure(String ErrorMsg) { + ToastUtils.error("启动通道校准失败!"); + } + }); + } catch (Exception e) { + } + } + }).start(); + } + //endregion + + //region 补偿校准 + public void SaveBCJZ() { + Short H = 0; + Short L = 0; + Short time = 0; + try { + H = Short.parseShort(bcjz_gxs.getText().toString()); + L = Short.parseShort(bcjz_dxs.getText().toString()); + int ftime = (int) Math.round((Double.parseDouble(bcjz_clsj.getText().toString()) * 10)); + time = (short) ftime; + } catch (Exception ex) { + ToastUtils.error("数据不合法,保存变量失败!" + ex.getMessage()); + return; + } + Short finalH = H; + Short finalL = L; + Short finalTime = time; + + lcMode.Gxs = bcjz_gxs.getText().toString(); + lcMode.Lxs = bcjz_dxs.getText().toString(); + lcMode.tdclsj = bcjz_clsj.getText().toString(); + + new Thread(new Runnable() { + @Override + public void run() { + try { + ExecuteTheRecipe.WritePLC("高系数" + lcMode.num, finalH, null); + ExecuteTheRecipe.WritePLC("低系数" + lcMode.num, finalL, null); + ExecuteTheRecipe.WritePLC("补偿" + lcMode.num + "时间", finalTime, new IWriteCallBack() { + @Override + public void onSuccess() { + ToastUtils.info("保存变量成功!"); + QueryDB.UpdateSilosisOpenbcsf(lcMode.id, bcjz_gxs.getText().toString(), + bcjz_dxs.getText().toString(), bcjz_clsj.getText().toString()); + } + + @Override + public void onFailure(String ErrorMsg) { + ToastUtils.warning("保存变量失败!"); + } + }); + } catch (Exception e) { + + } + } + }).start(); + + } + //endregion + + //region 定时器 /** - * 设置数据 - * @param + * 启动定时器 */ - public void SetData(lcMode _lcMode, FragmentManager _fragmentManager) - { - this.lcMode=_lcMode; - this.fragmentManager=_fragmentManager; + public void StartTime() { + runtime.setBase(SystemClock.elapsedRealtime()); + runtime.start(); + new Thread(new Runnable() { + @Override + public void run() { + try { + //自动模式 + ExecuteTheRecipe.WritePLC("手自切换", false, null); + //开启 + ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, true, null); + } catch (Exception e) { - initData(); + } + } + }).start(); + } + + /** + * 停止定时器 + */ + public int StopTime() { + long elapsedMillis = SystemClock.elapsedRealtime() - runtime.getBase(); + runtime.stop(); + int time = (int) (elapsedMillis / 1000); + new Thread(new Runnable() { + @Override + public void run() { + try { + ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, false, null); + } catch (Exception e) { + + } + } + }).start(); + return time;//当前点击多少秒 } + //endregion } diff --git a/app/src/main/res/layout/item/layout/fragment_silos_item_jiaoyan.xml b/app/src/main/res/layout/item/layout/fragment_silos_item_jiaoyan.xml index db9979e3..6579f95b 100644 --- a/app/src/main/res/layout/item/layout/fragment_silos_item_jiaoyan.xml +++ b/app/src/main/res/layout/item/layout/fragment_silos_item_jiaoyan.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".modules.home.fragment.mode.Silos_item_jiaoyan_fragment"> + > diff --git a/app/src/main/res/layout/item/layout/silos_jiaoyan_item.xml b/app/src/main/res/layout/item/layout/silos_jiaoyan_item.xml index 22e5501e..f05eee30 100644 --- a/app/src/main/res/layout/item/layout/silos_jiaoyan_item.xml +++ b/app/src/main/res/layout/item/layout/silos_jiaoyan_item.xml @@ -14,20 +14,75 @@ android:layout_margin="10dp" android:background="@drawable/common_bg_with_radius_and_border"> - + android:layout_marginTop="15dp" + android:layout_width="wrap_content" + android:layout_height="wrap_content"> + + + + + + + + + + + + + + + - - - - - - - + android:layout_height="match_parent"> + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file