From 12b561520e831b5834cf4cf805788af6e55c81b4 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: Fri, 12 Apr 2024 17:15:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=8C=E9=9D=A2=E5=B0=8F=E7=82=92=E5=90=88?= =?UTF-8?q?=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/gradle.xml | 5 +- .idea/misc.xml | 2 +- app/build.gradle | 4 + app/src/main/AndroidManifest.xml | 62 +- .../bonait/bnframework/HBL/API/APIHelper.java | 535 ++++++++++++ .../bonait/bnframework/HBL/API/APIResult.java | 21 + .../bnframework/HBL/API/APIResultT.java | 21 + .../com/bonait/bnframework/HBL/API/Utils.java | 57 ++ .../HBL/Communication/CommBase.java | 44 + .../Communication/Modbus/ExceptionServer.java | 83 ++ .../Modbus/IExceptionHandling.java | 15 + .../Communication/Modbus/IModbusMaster.java | 10 + .../HBL/Communication/Modbus/IRead.java | 24 + .../HBL/Communication/Modbus/IWrite.java | 23 + .../Communication/Modbus/ModbusMaster.java | 695 ++++++++++++++++ .../HBL/Communication/Siemens/CommHelper.java | 157 ++++ .../Communication/Siemens/SiemensHelper.java | 360 ++++++++ .../HBL/CustomView/ShadowContainer.java | 213 +++++ .../bnframework/HBL/DataUtil/ByteLib.java | 81 ++ .../HBL/DataUtil/ByteTransDataFormat.java | 51 ++ .../bnframework/HBL/DataUtil/Convert.java | 107 +++ .../HBL/DataUtil/DataConvertLib.java | 244 ++++++ .../bnframework/HBL/DataUtil/DataType.java | 12 + .../bnframework/HBL/DataUtil/FloatLib.java | 31 + .../bnframework/HBL/DataUtil/IntLib.java | 51 ++ .../HBL/DataUtil/NotifyPropVar.java | 37 + .../bnframework/HBL/DataUtil/ShortLib.java | 51 ++ .../HBL/Dialog/AlertDialogButton.java | 8 + .../HBL/Dialog/DialogActivity.java | 15 + .../bnframework/HBL/Dialog/DialogManager.java | 309 +++++++ .../bnframework/HBL/Dialog/DialogType.java | 7 + .../bnframework/HBL/Dialog/DialogView.java | 35 + .../bnframework/HBL/Dialog/IDialogAction.java | 6 + .../bnframework/HBL/Enum/DataFormat.java | 8 + .../com/bonait/bnframework/HBL/Executor.java | 40 + .../bnframework/HBL/Interface/IRun.java | 5 + .../helper/I => HBL/Interface}/IRunT.java | 4 +- .../bnframework/HBL/Interface/IRunT2.java | 5 + .../HBL/Logs/IMessageLogNotify.java | 7 + .../bnframework/HBL/Logs/MessageLog.java | 62 ++ .../bonait/bnframework/HBL/NetworkUtils.java | 230 ++++++ .../bonait/bnframework/HBL/NotifyEvent.java | 60 ++ .../bnframework/HBL/Result/IResult.java | 30 + .../bnframework/HBL/Result/OperateResult.java | 78 ++ .../HBL/Result/OperateResultT.java | 88 ++ .../bnframework/HBL/Result/ResultCode.java | 38 + .../bnframework/HBL/Thread/IThread.java | 5 + .../HBL/Thread/IThreadComplete.java | 7 + .../bnframework/HBL/Thread/ThreadManager.java | 105 +++ .../bnframework/HBL/Thread/ThreadModel.java | 8 + .../{common/helper => HBL/Trig}/RTrig.java | 6 +- .../bonait/bnframework/MainApplication.java | 2 - .../welcome/model => Model}/AppLoginPo.java | 2 +- .../mine/model => Model}/UpdateAppPo.java | 2 +- .../from/fragment => Model}/UserInfo.java | 2 +- .../bnframework/Service/AnalogConvert.java | 136 +++ .../bnframework/Service/ControlAdress.java | 13 + .../com/bonait/bnframework/Service/Func.java | 24 + .../bnframework/Service/ModbusHelper.java | 206 +++++ .../bnframework/Service/OperationModel.java | 16 + .../bonait/bnframework/Service/PLCModel.java | 23 + .../BottomNavigation2Activity.java | 60 +- .../BottomNavigationNewActivity.java | 76 +- .../BunkerSetupActivity.java | 14 +- .../ActivityViewModel}/CookingActivity.java | 30 +- .../CookingSimulatedActivity.java | 21 +- .../ActivityViewModel}/CpActivity.java | 14 +- .../ActivityViewModel}/CpxzActivity.java | 6 +- .../ActivityViewModel}/DishTestActivity.java | 25 +- .../ActivityViewModel}/DiyActivity.java | 25 +- .../ActivityViewModel}/DiyMemoryActivity.java | 34 +- .../DiyUpdate1Activity.java | 12 +- .../ActivityViewModel}/DiyUpdateActivity.java | 15 +- .../ActivityViewModel}/FileActivity.java | 2 +- .../ImageChooseActivity.java | 13 +- .../ActivityViewModel}/LoginActivity.java | 10 +- .../ActivityViewModel}/NoticeActivity.java | 2 +- .../ActivityViewModel}/SzActivity.java | 15 +- .../ActivityViewModel}/UserActivity.java | 36 +- .../ActivityViewModel}/WelcomeActivity.java | 6 +- .../ActivityViewModel}/WhActivity.java | 13 +- .../Adapter}/FragmentAdapter.java | 2 +- .../Adapter}/gongxubuzhou_adapter.java | 2 +- .../Adapter}/gongxubuzhou_adapter1.java | 2 +- .../Adapter}/gongxubuzhou_adapter2.java | 2 +- .../Adapter}/good_adapter.java | 9 +- .../Adapter}/image_sp_adapter.java | 8 +- .../Adapter}/lc_adapter.java | 15 +- .../Adapter}/lcsz_adapter.java | 2 +- .../Adapter}/monitor_adapter.java | 2 +- .../Adapter}/process_adapter.java | 3 +- .../Adapter}/processchid_adapter.java | 2 +- .../Adapter}/sp_adapter.java | 2 +- .../Adapter}/user_adapter.java | 2 +- .../Adapter}/wl_adapter.java | 2 +- .../CustomView}/LocationStatus.java | 2 +- .../CustomView}/MyStatus.java | 2 +- .../CustomView}/QDListSectionAdapter.java | 8 +- .../CustomView}/QDSectionHeaderView.java | 2 +- .../CustomView}/SectionHeader.java | 2 +- .../CustomView}/SectionItem.java | 2 +- .../CustomView}/add_qupenren.java | 12 +- .../CustomView}/add_silos_message.java | 7 +- .../CustomView}/fragment_gx.java | 6 +- .../CustomView}/fragment_plc.java | 2 +- .../CustomView}/fragment_plc_control.java | 2 +- .../CustomView}/fragment_silos_cl.java | 13 +- .../CustomView}/huoli_control.java | 2 +- .../CustomView}/image_sp.java | 2 +- .../CustomView}/imagebuttom.java | 2 +- .../CustomView}/imagebuttom3.java | 2 +- .../CustomView}/imagebutton_control.java | 2 +- .../CustomView}/item_gx.java | 2 +- .../CustomView}/jingdutiao.java | 2 +- .../CustomView}/jingdutiao1.java | 2 +- .../CustomView}/newhuoli_control.java | 2 +- .../FragmentViewModel}/Home1Fragment.java | 86 +- .../FragmentViewModel}/Home2Fragment.java | 15 +- .../FragmentViewModel}/Home3Fragment.java | 2 +- .../FragmentViewModel}/Home4Fragment.java | 16 +- .../FragmentViewModel}/HomeFragmentPR.java | 25 +- .../FragmentViewModel}/HomeFragmentSBKZ.java | 34 +- .../FragmentViewModel}/MyFragment.java | 8 +- .../SystemCsControlFragment.java | 6 +- .../SystemCsFltlFragment.java | 10 +- .../SystemCsMonitorFragment.java | 7 +- .../SystemCsPLCFragment.java | 14 +- .../SystemDeviceinFragment.java | 2 +- .../SystemSeasoningsetFragment.java | 8 +- .../SystemSystemsetFragment.java | 2 +- .../systeminternetfragment.java | 19 +- .../bnframework/business/ConfigData.java | 68 +- .../business/ExecuteTheRecipe.java | 199 ++--- .../bonait/bnframework/business/MainInit.java | 135 ++- .../common/constant/ConfigName.java | 57 +- .../bnframework/common/constant/DataBus.java | 20 +- .../common/db/mode/BPA_CALIBRATION_PAR.java | 18 + .../adapter/FilePickerShowAdapter.java | 5 - .../common/helper/I/IMessageLogNotify.java | 13 - .../common/helper/I/IReadCallBack.java | 5 - .../bnframework/common/helper/I/IRun.java | 5 - .../bnframework/common/helper/I/IThread.java | 7 - .../common/helper/I/IWriteCallBack.java | 7 - .../bnframework/common/helper/MQTT.java | 3 +- .../bnframework/common/helper/MessageLog.java | 89 -- .../common/helper/ThreadManager.java | 75 -- .../common/helper/mode/ThreadModel.java | 9 - .../http/callback/json/JsonCallback.java | 4 +- .../common/modbus/ModbusTcpHelper.java | 44 - .../common/modbus/ModbusTcpServer.java | 771 ------------------ .../bnframework/common/oss/OssHelper.java | 3 +- .../common/utils/UpdateAppUtils.java | 7 - .../bonait/bnframework/test/TestActivity.java | 4 +- app/src/main/res/drawable/bg_btn_cancel.xml | 27 + .../res/drawable/bg_btn_dialog_qupenren.xml | 27 + app/src/main/res/drawable/dialog_back.xml | 5 + .../res/drawable/dialog_error_title_back.xml | 5 + .../res/drawable/dialog_info_title_back.xml | 5 + .../res/drawable/dialog_warn_title_back.xml | 5 + .../layout/activity_bottom_navigation2.xml | 2 +- .../layout/activity_bottom_navigation_new.xml | 6 +- .../main/res/layout/activity_bunkersetup.xml | 14 +- app/src/main/res/layout/activity_cooking.xml | 30 +- .../res/layout/activity_cookingsimulated.xml | 26 +- app/src/main/res/layout/activity_cp.xml | 2 +- app/src/main/res/layout/activity_cpxz.xml | 2 +- app/src/main/res/layout/activity_dialog.xml | 84 ++ app/src/main/res/layout/activity_dishtest.xml | 36 +- app/src/main/res/layout/activity_diy.xml | 2 +- .../main/res/layout/activity_diy_memory.xml | 4 +- .../main/res/layout/activity_diy_update.xml | 2 +- .../main/res/layout/activity_diy_update1.xml | 2 +- app/src/main/res/layout/activity_file.xml | 2 +- .../main/res/layout/activity_image_choose.xml | 2 +- app/src/main/res/layout/activity_login.xml | 2 +- app/src/main/res/layout/activity_notice.xml | 2 +- app/src/main/res/layout/activity_sz.xml | 2 +- app/src/main/res/layout/activity_user.xml | 2 +- app/src/main/res/layout/activity_welcome.xml | 2 +- app/src/main/res/layout/activity_wh.xml | 2 +- app/src/main/res/layout/fragment_home1.xml | 10 +- app/src/main/res/layout/fragment_home_pr.xml | 2 +- .../main/res/layout/fragment_home_sbkz.xml | 42 +- app/src/main/res/layout/fragment_my.xml | 2 +- .../res/layout/fragment_system_cs_control.xml | 2 +- .../res/layout/fragment_system_cs_fltl.xml | 2 +- .../res/layout/fragment_system_cs_monitor.xml | 2 +- .../res/layout/fragment_system_cs_plc.xml | 2 +- .../res/layout/fragment_system_devicein.xml | 2 +- .../res/layout/fragment_system_internet.xml | 2 +- .../layout/fragment_system_seasoningset.xml | 2 +- .../res/layout/fragment_system_systemset.xml | 2 +- .../item/layout/dialog_silos_message.xml | 2 +- app/src/main/res/mipmap-xxxhdpi/lcsz.png | Bin 0 -> 39638 bytes app/src/main/res/values/attrs.xml | 12 + app/src/main/res/values/styles.xml | 18 + 196 files changed, 5329 insertions(+), 2029 deletions(-) create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/API/APIHelper.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/API/APIResult.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/API/APIResultT.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/API/Utils.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Communication/CommBase.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ExceptionServer.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IExceptionHandling.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IModbusMaster.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IRead.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IWrite.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ModbusMaster.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Communication/Siemens/CommHelper.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Communication/Siemens/SiemensHelper.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/CustomView/ShadowContainer.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/DataUtil/ByteLib.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/DataUtil/ByteTransDataFormat.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/DataUtil/Convert.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/DataUtil/DataConvertLib.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/DataUtil/DataType.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/DataUtil/FloatLib.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/DataUtil/IntLib.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/DataUtil/NotifyPropVar.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/DataUtil/ShortLib.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Dialog/AlertDialogButton.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogActivity.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogManager.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogType.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogView.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Dialog/IDialogAction.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Enum/DataFormat.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Executor.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Interface/IRun.java rename app/src/main/java/com/bonait/bnframework/{common/helper/I => HBL/Interface}/IRunT.java (51%) create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Interface/IRunT2.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Logs/IMessageLogNotify.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Logs/MessageLog.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/NetworkUtils.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/NotifyEvent.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Result/IResult.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Result/OperateResult.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Result/OperateResultT.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Result/ResultCode.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Thread/IThread.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Thread/IThreadComplete.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Thread/ThreadManager.java create mode 100644 app/src/main/java/com/bonait/bnframework/HBL/Thread/ThreadModel.java rename app/src/main/java/com/bonait/bnframework/{common/helper => HBL/Trig}/RTrig.java (89%) rename app/src/main/java/com/bonait/bnframework/{modules/welcome/model => Model}/AppLoginPo.java (96%) rename app/src/main/java/com/bonait/bnframework/{modules/mine/model => Model}/UpdateAppPo.java (97%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from/fragment => Model}/UserInfo.java (85%) create mode 100644 app/src/main/java/com/bonait/bnframework/Service/AnalogConvert.java create mode 100644 app/src/main/java/com/bonait/bnframework/Service/ControlAdress.java create mode 100644 app/src/main/java/com/bonait/bnframework/Service/Func.java create mode 100644 app/src/main/java/com/bonait/bnframework/Service/ModbusHelper.java create mode 100644 app/src/main/java/com/bonait/bnframework/Service/OperationModel.java create mode 100644 app/src/main/java/com/bonait/bnframework/Service/PLCModel.java rename app/src/main/java/com/bonait/bnframework/{modules/home/activity => ViewModel/ActivityViewModel}/BottomNavigation2Activity.java (76%) rename app/src/main/java/com/bonait/bnframework/{modules/home/activity => ViewModel/ActivityViewModel}/BottomNavigationNewActivity.java (89%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from => ViewModel/ActivityViewModel}/BunkerSetupActivity.java (90%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from => ViewModel/ActivityViewModel}/CookingActivity.java (92%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from => ViewModel/ActivityViewModel}/CookingSimulatedActivity.java (96%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from => ViewModel/ActivityViewModel}/CpActivity.java (95%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from => ViewModel/ActivityViewModel}/CpxzActivity.java (94%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from => ViewModel/ActivityViewModel}/DishTestActivity.java (97%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from => ViewModel/ActivityViewModel}/DiyActivity.java (95%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from => ViewModel/ActivityViewModel}/DiyMemoryActivity.java (94%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from => ViewModel/ActivityViewModel}/DiyUpdate1Activity.java (98%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from => ViewModel/ActivityViewModel}/DiyUpdateActivity.java (97%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from => ViewModel/ActivityViewModel}/FileActivity.java (98%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from => ViewModel/ActivityViewModel}/ImageChooseActivity.java (84%) rename app/src/main/java/com/bonait/bnframework/{modules/welcome/activity => ViewModel/ActivityViewModel}/LoginActivity.java (97%) rename app/src/main/java/com/bonait/bnframework/{modules/mine/fragment/from => ViewModel/ActivityViewModel}/NoticeActivity.java (97%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from => ViewModel/ActivityViewModel}/SzActivity.java (89%) rename app/src/main/java/com/bonait/bnframework/{modules/mine/fragment => ViewModel/ActivityViewModel}/UserActivity.java (89%) rename app/src/main/java/com/bonait/bnframework/{modules/welcome/activity => ViewModel/ActivityViewModel}/WelcomeActivity.java (96%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from => ViewModel/ActivityViewModel}/WhActivity.java (91%) rename app/src/main/java/com/bonait/bnframework/{modules/home/adapter => ViewModel/Adapter}/FragmentAdapter.java (94%) rename app/src/main/java/com/bonait/bnframework/{modules/home/adapter => ViewModel/Adapter}/gongxubuzhou_adapter.java (97%) rename app/src/main/java/com/bonait/bnframework/{modules/home/adapter => ViewModel/Adapter}/gongxubuzhou_adapter1.java (97%) rename app/src/main/java/com/bonait/bnframework/{modules/home/adapter => ViewModel/Adapter}/gongxubuzhou_adapter2.java (97%) rename app/src/main/java/com/bonait/bnframework/{modules/home/adapter => ViewModel/Adapter}/good_adapter.java (96%) rename app/src/main/java/com/bonait/bnframework/{modules/home/adapter => ViewModel/Adapter}/image_sp_adapter.java (92%) rename app/src/main/java/com/bonait/bnframework/{modules/home/adapter => ViewModel/Adapter}/lc_adapter.java (95%) rename app/src/main/java/com/bonait/bnframework/{modules/home/adapter => ViewModel/Adapter}/lcsz_adapter.java (97%) rename app/src/main/java/com/bonait/bnframework/{modules/home/adapter => ViewModel/Adapter}/monitor_adapter.java (98%) rename app/src/main/java/com/bonait/bnframework/{modules/home/adapter => ViewModel/Adapter}/process_adapter.java (96%) rename app/src/main/java/com/bonait/bnframework/{modules/home/adapter => ViewModel/Adapter}/processchid_adapter.java (97%) rename app/src/main/java/com/bonait/bnframework/{modules/home/adapter => ViewModel/Adapter}/sp_adapter.java (98%) rename app/src/main/java/com/bonait/bnframework/{modules/home/adapter => ViewModel/Adapter}/user_adapter.java (98%) rename app/src/main/java/com/bonait/bnframework/{modules/home/adapter => ViewModel/Adapter}/wl_adapter.java (97%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/LocationStatus.java (59%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/MyStatus.java (56%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/QDListSectionAdapter.java (96%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/QDSectionHeaderView.java (97%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/SectionHeader.java (97%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/SectionItem.java (98%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/add_qupenren.java (91%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/add_silos_message.java (97%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/fragment_gx.java (95%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/fragment_plc.java (98%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/fragment_plc_control.java (99%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/fragment_silos_cl.java (82%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/huoli_control.java (99%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/image_sp.java (55%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/imagebuttom.java (98%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/imagebuttom3.java (98%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/imagebutton_control.java (97%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/item_gx.java (78%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/jingdutiao.java (95%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/jingdutiao1.java (98%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/mode => ViewModel/CustomView}/newhuoli_control.java (99%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment => ViewModel/FragmentViewModel}/Home1Fragment.java (92%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment => ViewModel/FragmentViewModel}/Home2Fragment.java (86%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment => ViewModel/FragmentViewModel}/Home3Fragment.java (96%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment => ViewModel/FragmentViewModel}/Home4Fragment.java (86%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment => ViewModel/FragmentViewModel}/HomeFragmentPR.java (90%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment => ViewModel/FragmentViewModel}/HomeFragmentSBKZ.java (94%) rename app/src/main/java/com/bonait/bnframework/{modules/mine/fragment => ViewModel/FragmentViewModel}/MyFragment.java (98%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from/fragment => ViewModel/FragmentViewModel}/SystemCsControlFragment.java (93%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from/fragment => ViewModel/FragmentViewModel}/SystemCsFltlFragment.java (87%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from/fragment => ViewModel/FragmentViewModel}/SystemCsMonitorFragment.java (93%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from/fragment => ViewModel/FragmentViewModel}/SystemCsPLCFragment.java (88%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from/fragment => ViewModel/FragmentViewModel}/SystemDeviceinFragment.java (98%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from/fragment => ViewModel/FragmentViewModel}/SystemSeasoningsetFragment.java (98%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from/fragment => ViewModel/FragmentViewModel}/SystemSystemsetFragment.java (99%) rename app/src/main/java/com/bonait/bnframework/{modules/home/fragment/from/fragment => ViewModel/FragmentViewModel}/systeminternetfragment.java (88%) create mode 100644 app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_CALIBRATION_PAR.java delete mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/I/IMessageLogNotify.java delete mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/I/IReadCallBack.java delete mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/I/IRun.java delete mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/I/IThread.java delete mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/I/IWriteCallBack.java delete mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/MessageLog.java delete mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/ThreadManager.java delete mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/mode/ThreadModel.java delete mode 100644 app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpHelper.java delete mode 100644 app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpServer.java create mode 100644 app/src/main/res/drawable/bg_btn_cancel.xml create mode 100644 app/src/main/res/drawable/bg_btn_dialog_qupenren.xml create mode 100644 app/src/main/res/drawable/dialog_back.xml create mode 100644 app/src/main/res/drawable/dialog_error_title_back.xml create mode 100644 app/src/main/res/drawable/dialog_info_title_back.xml create mode 100644 app/src/main/res/drawable/dialog_warn_title_back.xml create mode 100644 app/src/main/res/layout/activity_dialog.xml create mode 100644 app/src/main/res/mipmap-xxxhdpi/lcsz.png diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 6e5389ed..804e304a 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,16 +4,15 @@ diff --git a/.idea/misc.xml b/.idea/misc.xml index cba3440e..c3df9b04 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index c41cc1e3..db84ce9e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,6 +34,7 @@ android { } compileOptions { + coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } @@ -155,6 +156,9 @@ dependencies { implementation 'com.github.SheHuan:NiceImageView:1.0.5' + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.6' + implementation 'com.github.xingshuangs:iot-communication:1.5.0' + //MQTT // implementation files('libs\\org.eclipse.paho.android.service-1.1.1.jar') // implementation files('libs\\org.eclipse.paho.client.mqttv3-1.2.5.jar') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8fe53452..87c80ac2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,96 +34,96 @@ tools:node="merge" tools:replace="android:icon"> @@ -146,10 +146,10 @@ - + - + @@ -165,7 +165,7 @@ --> - + retstr = new AtomicReference<>(""); + List fields = Arrays.asList(t.getClass().getFields()); + Collections.sort(fields, Comparator.comparing(Field::getName)); + fields.forEach(item->{ + if( item.getName().toUpperCase()!="sign".toUpperCase()){ + try { + if(item.get(t)!=null&&!item.get(t).toString().isEmpty()){ + Type type = item.getGenericType(); + String typeName = type.toString(); + switch(typeName){ + case "class java.util.Date": + case "class java.lang.String": + case "byte": + case "int": + case "float": + case "double": + case "long": + case "short": + case "boolean": + retstr.set(retstr.get() + item.getName() + "=" + item.get(t) + "&"); + break; + default: +// String a= new GsonBuilder().serializeNulls().create().toJson(item.get(t));//保留为空的属性 + String a= new Gson().toJson(item.get(t)); + retstr.set(retstr.get() + item.getName() + "=" + a + "&"); + break; + } + } + } catch (Exception e) { + } + } + }); + String tempSign="&key="+key; + if(retstr.get().length()>0){ + tempSign=retstr.get().substring(0, retstr.get().length()-1)+"&key="+key; + } +// String tempSign=retstr.get().substring(0, retstr.get().length()-1)+"&key="+key; + StringBuilder sb = new StringBuilder(); + try{ + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] digest = md.digest(tempSign.toUpperCase().getBytes()); + for (byte b : digest) { + sb.append(Integer.toHexString((b & 0xFF) | 0x100).substring(1,3)); + } + }catch (Exception e){ + + } + return sb.toString().toUpperCase(); + } + + public static String Post(String url, Map parameters, Map headers) throws IOException { + HttpURLConnection connection = null; + InputStream inputStream = null; + BufferedReader reader = null; + StringBuffer buffer = new StringBuffer(); + try { + URL requestUrl = new URL(url); + connection = (HttpURLConnection) requestUrl.openConnection(); + connection.setRequestMethod("POST"); + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + connection.setDoOutput(true); + connection.setDoInput(true); + // 设置header + if (headers != null) { + for (Map.Entry entry : headers.entrySet()) { + connection.setRequestProperty(entry.getKey(), entry.getValue()); + } + } + // 设置参数 + if (parameters != null) { + StringBuilder stringBuilder = new StringBuilder(); + for (Map.Entry entry : parameters.entrySet()) { + stringBuilder.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(), "UTF-8")).append("&"); + } + String params = stringBuilder.toString(); + byte[] postData = params.getBytes("UTF-8"); + connection.setRequestProperty("Content-Length", Integer.toString(postData.length)); + try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { + outputStream.write(postData); + } + } + // 获取响应结果 + int statusCode = connection.getResponseCode(); + if (statusCode == HttpURLConnection.HTTP_OK) { + inputStream = connection.getInputStream(); + reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); + String line; + while ((line = reader.readLine()) != null) { + buffer.append(line); + } + } else { + throw new IOException("服务器返回错误,状态码:" + statusCode); + } + }catch (Exception e){ + MessageLog.ShowError("POST 请求异常:"+e.toString()); + }finally { + // 关闭连接和流 + if (reader != null) { + reader.close(); + } + if (inputStream != null) { + inputStream.close(); + } + if (connection != null) { + connection.disconnect(); + } + } + return buffer.toString(); + } + public static String Post(String url, String body, Map headers) throws IOException { + HttpURLConnection connection = null; + InputStream inputStream = null; + BufferedReader reader = null; + StringBuffer buffer = new StringBuffer(); + try { + URL requestUrl = new URL(url); + connection = (HttpURLConnection) requestUrl.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");// "Fiddler" + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestProperty("Charset", "UTF-8"); + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + connection.setDoOutput(true); + connection.setDoInput(true); + // 设置header + if (headers != null) { + for (Map.Entry entry : headers.entrySet()) { + connection.setRequestProperty(entry.getKey(), entry.getValue()); + } + } + // 设置参数 + if (!body .isEmpty()) { + connection.setRequestProperty("Content-Length", Integer.toString(body.getBytes().length)); + try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { + outputStream.write(body.getBytes()); + } + } + // 获取响应结果 + int statusCode = connection.getResponseCode(); + if (statusCode == HttpURLConnection.HTTP_OK) { + inputStream = connection.getInputStream(); + reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); + String line; + while ((line = reader.readLine()) != null) { + buffer.append(line); + } + } else { + throw new IOException("服务器返回错误,状态码:" + statusCode); + } + }catch (Exception e){ + MessageLog.ShowError("POST 请求异常:"+e.toString()); + }finally { + // 关闭连接和流 + if (reader != null) { + reader.close(); + } + if (inputStream != null) { + inputStream.close(); + } + if (connection != null) { + connection.disconnect(); + } + } + return buffer.toString(); + } + public static String Post(String url, Object body, Map headers) throws IOException { + HttpURLConnection connection = null; + InputStream inputStream = null; + BufferedReader reader = null; + StringBuffer buffer = new StringBuffer(); + try { + URL requestUrl = new URL(url); + connection = (HttpURLConnection) requestUrl.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");// "Fiddler" + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestProperty("Charset", "UTF-8"); + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + connection.setDoOutput(true); + connection.setDoInput(true); + // 设置header + if (headers != null) { + for (Map.Entry entry : headers.entrySet()) { + connection.setRequestProperty(entry.getKey(), entry.getValue()); + } + } + // 设置参数 + if (body !=null) { + byte[] bytes = new Gson().toJson(body).getBytes(); + connection.setRequestProperty("Content-Length", Integer.toString(bytes.length)); + try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { + outputStream.write(bytes); + } + } + // 获取响应结果 + int statusCode = connection.getResponseCode(); + if (statusCode == HttpURLConnection.HTTP_OK) { + inputStream = connection.getInputStream(); + reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); + String line; + while ((line = reader.readLine()) != null) { + buffer.append(line); + } + } else { + throw new IOException("服务器返回错误,状态码:" + statusCode); + } + }catch (Exception e){ + MessageLog.ShowError("POST 请求异常:"+e.toString()); + }finally { + // 关闭连接和流 + if (reader != null) { + reader.close(); + } + if (inputStream != null) { + inputStream.close(); + } + if (connection != null) { + connection.disconnect(); + } + } + return buffer.toString(); + } + public static void Post(String url, Object body, IRunT callback) { + new Thread(()->{ + HttpURLConnection connection = null; + InputStream inputStream = null; + BufferedReader reader = null; + StringBuffer buffer = new StringBuffer(); + try { + URL requestUrl = new URL(url); + connection = (HttpURLConnection) requestUrl.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");// "Fiddler" + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestProperty("Charset", "UTF-8"); + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + connection.setDoOutput(true); + connection.setDoInput(true); + + if(body!=null){ + //获取签名信息 + String sign = GetSign(body,key); + + //设置请求头 + connection.setRequestProperty("key", key); + connection.setRequestProperty("sign", sign); + + + //设置请求 body + byte[] bytes = new Gson().toJson(body).getBytes(); + connection.setRequestProperty("Content-Length", Integer.toString(bytes.length)); + try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { + outputStream.write(bytes); + } + } + + // 获取响应结果 + int statusCode = connection.getResponseCode(); + if (statusCode == HttpURLConnection.HTTP_OK) { + inputStream = connection.getInputStream(); + reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); + String line; + while ((line = reader.readLine()) != null) { + buffer.append(line); + } + } else { + throw new IOException("服务器返回错误,状态码:" + statusCode); + } + }catch (Exception e){ + MessageLog.ShowError("POST 请求异常:"+e.toString()); + return; + }finally { + try{ + // 关闭连接和流 + if (reader != null) reader.close(); + + if (inputStream != null) inputStream.close(); + + if (connection != null) connection.disconnect(); + + }catch(Exception e){ + MessageLog.ShowError("POST 请求异常:"+e.toString()); + return; + } + } + + try{ + APIResult res = new GsonBuilder().serializeNulls().create().fromJson(buffer.toString(), APIResult.class); + if(res!=null)if(callback!=null) callback.Run(res); + }catch(Exception e){ + + } + }).start(); + + } + public static void Post(String url, Object body,String signkey, IRunT callback) { + new Thread(()->{ + HttpURLConnection connection = null; + InputStream inputStream = null; + BufferedReader reader = null; + StringBuffer buffer = new StringBuffer(); + try { + URL requestUrl = new URL(url); + connection = (HttpURLConnection) requestUrl.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");// "Fiddler" + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestProperty("Charset", "UTF-8"); + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + connection.setDoOutput(true); + connection.setDoInput(true); + + if(body!=null){ + //获取签名信息 + String sign = GetSign(body,signkey); + + MessageLog.ShowInfo("签名信息:"+sign); + + //设置请求头 + connection.setRequestProperty("key", signkey); +// connection.setRequestProperty("sign", sign); + + + //设置请求 body + byte[] bytes = new Gson().toJson(body).getBytes(); + connection.setRequestProperty("Content-Length", Integer.toString(bytes.length)); + try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { + outputStream.write(bytes); + } + } + + // 获取响应结果 + int statusCode = connection.getResponseCode(); + if (statusCode == HttpURLConnection.HTTP_OK) { + inputStream = connection.getInputStream(); + reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); + String line; + while ((line = reader.readLine()) != null) { + buffer.append(line); + } + } else { + throw new IOException("服务器返回错误,状态码:" + statusCode); + } + }catch (Exception e){ + MessageLog.ShowError("POST 请求异常:"+e.toString()); + return; + }finally { + try{ + // 关闭连接和流 + if (reader != null) reader.close(); + + if (inputStream != null) inputStream.close(); + + if (connection != null) connection.disconnect(); + + }catch(Exception e){ + MessageLog.ShowError("POST 请求异常:"+e.toString()); + return; + } + } + + try{ + APIResult res = new GsonBuilder().serializeNulls().create().fromJson(buffer.toString(), APIResult.class); + if(res!=null)if(callback!=null) callback.Run(res); + }catch(Exception e){ + MessageLog.ShowError("POST 请求异常:"+e.toString()); + } + }).start(); + + } + + public static void PostT(String url, Object body,String signkey ,IRunT> callback) { + new Thread(()->{ + HttpURLConnection connection = null; + InputStream inputStream = null; + BufferedReader reader = null; + StringBuffer buffer = new StringBuffer(); + try { + URL requestUrl = new URL(url); + connection = (HttpURLConnection) requestUrl.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");// "Fiddler" + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestProperty("Charset", "UTF-8"); + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + connection.setDoOutput(true); + connection.setDoInput(true); + + if(body!=null){ + //获取签名信息 + String sign = GetSign(body,signkey); + + //设置请求头 + connection.setRequestProperty("key", signkey); + connection.setRequestProperty("sign", sign); + + + //设置请求 body + byte[] bytes = new Gson().toJson(body).getBytes(); + connection.setRequestProperty("Content-Length", Integer.toString(bytes.length)); + try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { + outputStream.write(bytes); + } + } + + // 获取响应结果 + int statusCode = connection.getResponseCode(); + if (statusCode == HttpURLConnection.HTTP_OK) { + inputStream = connection.getInputStream(); + reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); + String line; + while ((line = reader.readLine()) != null) { + buffer.append(line); + } + } else { + throw new IOException("服务器返回错误,状态码:" + statusCode); + } + }catch (Exception e){ + MessageLog.ShowError("POST 请求异常:"+e.toString()); + return; + }finally { + try{ + // 关闭连接和流 + if (reader != null) reader.close(); + if (inputStream != null) inputStream.close(); + if (connection != null) connection.disconnect(); + }catch(Exception e){ + MessageLog.ShowError("POST 请求异常:"+e.toString()); + return; + } + } + try{ + + APIResultT res = new GsonBuilder().serializeNulls().create().fromJson(buffer.toString(), APIResultT.class); + if(res!=null)if(callback!=null) callback.Run(res); + }catch(Exception e){ + MessageLog.ShowError("POST请求返回值解析异常,"+e.toString()); + } + }).start(); + + } + public static void get(String urlAdd,Map params,IRunT callback) { + new Thread(()->{ + try { + String ResponseAdd = BuildUrlWithParams(urlAdd,params);//请求地址和参数 + URL url = new URL(ResponseAdd); + HttpURLConnection Connection = (HttpURLConnection) url.openConnection(); + Connection.setRequestMethod("GET"); + Connection.setConnectTimeout(3000); + Connection.setReadTimeout(3000); + int responseCode = Connection.getResponseCode(); + if (responseCode == Connection.HTTP_OK) { + InputStream inputStream = Connection.getInputStream(); + ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); + byte[] bytes = new byte[1024]; + int length = 0; + while ((length = inputStream.read(bytes)) != -1) { + arrayOutputStream.write(bytes, 0, length); + arrayOutputStream.flush();//强制释放缓冲区 + } + String s = arrayOutputStream.toString(); + if(callback!=null)callback.Run(s); + } else { + MessageLog.ShowError("get 请求失败"); + } + } catch (Exception e) { + MessageLog.ShowError(e); + } + }).start(); + } + + /** + * 请求参数拼接 + * @param Url 请求地址 + * @param params 请求参数 + * @return + */ + public static String BuildUrlWithParams(String Url,Map params){ + StringBuilder sb = new StringBuilder(Url); + if(params!=null&&!params.isEmpty()){ + sb.append("?"); + + params.forEach((key,value)->{ + sb.append(key).append("=").append(value).append("&"); + }); + + sb.deleteCharAt(sb.length()-1); + } + return sb.toString(); + } + +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/API/APIResult.java b/app/src/main/java/com/bonait/bnframework/HBL/API/APIResult.java new file mode 100644 index 00000000..0e0e76d7 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/API/APIResult.java @@ -0,0 +1,21 @@ +package com.bonait.bnframework.HBL.API; + +import com.google.gson.GsonBuilder; + +public class APIResult { + public int statusCode ; + + public Object data ; + + public String succeeded ; + + public String errors ; + + public String extras ; + + public int timestamp ; + + public String toString(){ + return new GsonBuilder().serializeNulls().create().toJson(this);//保留为空的属性 + } +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/API/APIResultT.java b/app/src/main/java/com/bonait/bnframework/HBL/API/APIResultT.java new file mode 100644 index 00000000..23753a8e --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/API/APIResultT.java @@ -0,0 +1,21 @@ +package com.bonait.bnframework.HBL.API; + +import com.google.gson.GsonBuilder; + +public class APIResultT { + public int statusCode ; + + public T data ; + + public String succeeded ; + + public String errors ; + + public String extras ; + + public int timestamp ; + + public String toString(){ + return new GsonBuilder().serializeNulls().create().toJson(this);//保留为空的属性 + } +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/API/Utils.java b/app/src/main/java/com/bonait/bnframework/HBL/API/Utils.java new file mode 100644 index 00000000..34d201f9 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/API/Utils.java @@ -0,0 +1,57 @@ +package com.bonait.bnframework.HBL.API; + +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.cert.X509Certificate; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +public class Utils { + + /** + * 禁用SSL验证 + */ + public static void disableSSLCertChecking() { + try { + TrustManager[] trustAllCerts = new TrustManager[]{ + new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } + + @Override + public void checkClientTrusted(X509Certificate[] certs, String authType) { + } + + @Override + public void checkServerTrusted(X509Certificate[] certs, String authType) { + } + } + }; + + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + + // Create all-trusting host name verifier + HostnameVerifier allHostsValid = new HostnameVerifier() { + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + + // Install the all-trusting host verifier + HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (KeyManagementException e) { + e.printStackTrace(); + } + } +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Communication/CommBase.java b/app/src/main/java/com/bonait/bnframework/HBL/Communication/CommBase.java new file mode 100644 index 00000000..6a163d48 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Communication/CommBase.java @@ -0,0 +1,44 @@ +package com.bonait.bnframework.HBL.Communication; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.LineNumberReader; + +public class CommBase { + /** + * Ping PLC地址是否通畅 + * @param address + * @param pingTimes ping的次数 + * @param timeOut 超时时间 10 + * @return + */ + public boolean NetPing(String address, int pingTimes, int timeOut) { + Process process = null; + try { + process = Runtime.getRuntime().exec( "ping " + "-c " + pingTimes + " -w " + timeOut+ " "+address); + InputStreamReader r = new InputStreamReader(process.getInputStream()); + LineNumberReader returnData = new LineNumberReader(r); + String returnMsg=""; + String line = ""; + while ((line = returnData.readLine()) != null) { + System.out.println(line); + returnMsg += line; + } + + if(returnMsg.indexOf("100% packet loss")!=-1){ + System.out.println("与 " +address +" 连接不畅通."); + //ToastUtils.info("与 " +address +" 连接不畅通."); + return false; + } else{ + System.out.println("与 " +address +" 连接畅通."); + //ToastUtils.info("与 " +address +" 连接不畅通."); + return true; + } + } catch (IOException e) { + // e.printStackTrace(); + } + return false; + + } + +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ExceptionServer.java b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ExceptionServer.java new file mode 100644 index 00000000..485e7f3c --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ExceptionServer.java @@ -0,0 +1,83 @@ +package com.bonait.bnframework.HBL.Communication.Modbus; + +import com.bonait.bnframework.HBL.Logs.MessageLog; +import com.licheedev.modbus4android.ModbusRespException; +import com.serotonin.modbus4j.exception.ModbusInitException; +import com.serotonin.modbus4j.exception.ModbusTransportException; + +import java.util.concurrent.ExecutionException; + +public class ExceptionServer { + + public ExceptionServer(String Address, int length,IExceptionHandling excpet) + { + try { + int add = GetAddress(Address); + if (add < 0) { + MessageLog.ShowError("地址解析失败=" + Address); + return; + } + if (excpet!=null) excpet.onSuccess(add); + } catch (InterruptedException e) { + if (excpet!=null) excpet.onFailure(e.toString()); + } catch (ExecutionException e) { + if (excpet!=null) excpet.onFailure(e.toString()); + } catch (ModbusTransportException e) { + if (excpet!=null) excpet.onFailure(e.toString()); + } catch (ModbusInitException e) { + if (excpet!=null) excpet.onFailure(e.toString()); + } catch (ModbusRespException e) { + if (excpet!=null) excpet.onFailure(e.toString()); + } + } + + public int GetAddress(String address) { + if (address == null) return -1; + if (address.length() > 0) { + address = address.trim(); + try{ + if (address.toUpperCase().contains("M") &&address.toUpperCase().contains(".")&& address.length() >= 4) { + String[] res = address.substring(1).split("[.]"); + if (res != null && res.length == 2) { + int firstAdd = Integer.parseInt(res[0]); + int endAdd = Integer.parseInt(res[1]); + if (endAdd >= 0 && endAdd <= 7) { + return (firstAdd * 8) + 320 + endAdd; + } + } + } else if (address.toUpperCase().contains("I") && address.length() >= 4) { + String[] res = address.substring(1).split("[.]"); + if (res != null && res.length == 2) { + int firstAdd = Integer.parseInt(res[0]); + int endAdd = Integer.parseInt(res[1]); + if (endAdd >= 0 && endAdd <= 7) { + return (firstAdd * 8) + endAdd; + } + } + } else if ((address.toUpperCase().contains("VW") || address.toUpperCase().contains("VD")) && address.length() >= 3) { + String res = address.substring(2); + if (res != null) { + int tempAdd = Integer.parseInt(res); + return (tempAdd / 2) + 100; + } + }else if (address.toUpperCase().contains("M")&&address.length() >=2){ + return Integer.parseInt(address.substring(1))+4000; + }else if (address.toUpperCase().contains("X")&&address.length() >=2){ + int xadd = Integer.parseInt( address.substring(1)); + return (xadd / 10 * 8) + xadd % 10; + }else if (address.toUpperCase().contains("Y")&&address.length() >=2){ + int yadd = Integer.parseInt( address.substring(1)); + return ((yadd / 10 * 8) + yadd % 10) + 300; + }else if (address.toUpperCase().contains("D")&&address.length() >=2){ + return Integer.parseInt( address.substring(1)); + } + else { + return Integer.parseInt(address); + } + }catch (Exception e){ + MessageLog.ShowError(e); + } + } + return -1; + } +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IExceptionHandling.java b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IExceptionHandling.java new file mode 100644 index 00000000..8569475e --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IExceptionHandling.java @@ -0,0 +1,15 @@ +package com.bonait.bnframework.HBL.Communication.Modbus; + +import com.licheedev.modbus4android.ModbusRespException; +import com.serotonin.modbus4j.exception.ModbusInitException; +import com.serotonin.modbus4j.exception.ModbusTransportException; + +import java.util.concurrent.ExecutionException; + +public interface IExceptionHandling { + void onSuccess(int add)throws InterruptedException, ExecutionException, ModbusTransportException, + ModbusInitException, ModbusRespException; + + + void onFailure(String error); +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IModbusMaster.java b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IModbusMaster.java new file mode 100644 index 00000000..f8b3f32a --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IModbusMaster.java @@ -0,0 +1,10 @@ +package com.bonait.bnframework.HBL.Communication.Modbus; + +import com.bonait.bnframework.HBL.Result.OperateResult; + +public interface IModbusMaster { + OperateResult TcpConnect(String ip, int port); + OperateResult RtuConnect(String com, int baudRate); + boolean getConnected(); + +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IRead.java b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IRead.java new file mode 100644 index 00000000..c7da05b1 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IRead.java @@ -0,0 +1,24 @@ +package com.bonait.bnframework.HBL.Communication.Modbus; + +import com.bonait.bnframework.HBL.Result.OperateResultT; + +public interface IRead { + + OperateResultT ReadBool(String address, int length); + OperateResultT ReadBool(String address); + OperateResultT ReadInputCoil(String address, int length); + OperateResultT ReadInputCoil(String address); + + OperateResultT ReadShort(String address, int length); + OperateResultT ReadShort(String address); + + OperateResultT ReadInt(String address, int length); + OperateResultT ReadInt(String address); + + OperateResultT ReadByte(String address, int length); + + OperateResultT ReadString(String address, int length); + + OperateResultT ReadFloat(String address, int length); + OperateResultT ReadFloat(String address); +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IWrite.java b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IWrite.java new file mode 100644 index 00000000..91c47f11 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/IWrite.java @@ -0,0 +1,23 @@ +package com.bonait.bnframework.HBL.Communication.Modbus; + +import com.bonait.bnframework.HBL.Result.OperateResult; + +public interface IWrite { + OperateResult WriteBool(String address, boolean value); + OperateResult WriteBool(String address, boolean[] value); + OperateResult WriteBool(String address, boolean[] value, int slaveId); + + OperateResult WriteShort(String address, short value); + OperateResult WriteShort(String address, short[] value); + OperateResult WriteShort(String address, short[] value, int slaveId); + + OperateResult WriteInt(String address, int value); + OperateResult WriteInt(String address, int[] value); + OperateResult WriteInt(String address, int[] value, int slaveId); + + OperateResult WriteString(String address, String value, int slaveId); + + OperateResult WriteFloat(String address, float value); + OperateResult WriteFloat(String address, float[] value); + OperateResult WriteFloat(String address, float[] value, int slaveId); +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ModbusMaster.java b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ModbusMaster.java new file mode 100644 index 00000000..766f975f --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ModbusMaster.java @@ -0,0 +1,695 @@ +package com.bonait.bnframework.HBL.Communication.Modbus; + +import static com.bonait.bnframework.HBL.DataUtil.DataConvertLib.ByteToShort; + +import com.bonait.bnframework.HBL.Communication.CommBase; +import com.bonait.bnframework.HBL.DataUtil.FloatLib; +import com.bonait.bnframework.HBL.DataUtil.IntLib; +import com.bonait.bnframework.HBL.DataUtil.ShortLib; +import com.bonait.bnframework.HBL.Enum.DataFormat; +import com.bonait.bnframework.HBL.Logs.MessageLog; +import com.bonait.bnframework.HBL.Result.OperateResult; +import com.bonait.bnframework.HBL.Result.OperateResultT; +import com.licheedev.modbus4android.ModbusCallback; +import com.licheedev.modbus4android.ModbusParam; +import com.licheedev.modbus4android.ModbusRespException; +import com.licheedev.modbus4android.ModbusWorker; +import com.licheedev.modbus4android.param.SerialParam; +import com.licheedev.modbus4android.param.TcpParam; +import com.serotonin.modbus4j.exception.ModbusInitException; +import com.serotonin.modbus4j.exception.ModbusTransportException; +import com.serotonin.modbus4j.msg.ReadCoilsResponse; +import com.serotonin.modbus4j.msg.ReadDiscreteInputsResponse; +import com.serotonin.modbus4j.msg.ReadHoldingRegistersResponse; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.atomic.AtomicReference; + +public class ModbusMaster implements IRead,IWrite ,IModbusMaster{ + + private boolean IsConnected=false; + + private ModbusWorker mw = new ModbusWorker(); + + public void DisConnect(){ mw.release(); } + + public boolean IsReconnection=true; + public DataFormat WriteDataFormat= DataFormat.ABCD; + + public DataFormat ReadDataFormat= DataFormat.BADC; + + public int SlaveId=1; + + @Override + public OperateResult TcpConnect(String ip, int port) { + try{ + MessageLog.ShowInfo("开始验证网络:"+ip ); + boolean status = false; + while (!status&&IsReconnection) { + try { + status =new CommBase().NetPing(ip,1,1);//status为0则代表通,为1则代表不通。 + Thread.sleep(1000); + } catch (Exception e) { + MessageLog.ShowInfo("设备 " + ip + " 网络验证失败"); + } + } + MessageLog.ShowInfo("开始连接Modbus TCP" ); + ModbusParam param= TcpParam.create(ip, port).setTimeout(1000).setRetries(0).setEncapsulated(false).setKeepAlive(true); + AtomicReference errorInfo=new AtomicReference<>(""); + while (IsConnected==false) + { + errorInfo.set(""); + mw.init(param, new ModbusCallback() { + @Override + public void onSuccess(com.serotonin.modbus4j.ModbusMaster modbusMaster) { + IsConnected=true; + MessageLog.ShowInfo("Modbus TCP 连接成功" ); + } + @Override + public void onFailure(Throwable tr) { + IsConnected = false; + errorInfo.set(tr.getMessage()); + MessageLog.ShowInfo("Modbus TCP 连接失败" ); + } + @Override + public void onFinally() { + + } + }); + if(!IsReconnection)break; + if(IsConnected==false) Thread.sleep(5000); + } + if(IsConnected)return OperateResult.CreateSuccess(); + else return OperateResult.CreateFailed(errorInfo.get()); + }catch(Exception ex){ + return OperateResult.CreateFailed(ex); + } + } + + @Override + public OperateResult RtuConnect(String com, int baudRate) { + try{ + MessageLog.ShowInfo("开始连接Modbus RTU" ); + ModbusParam param= SerialParam.create(com, baudRate) // 串口地址和波特率 + .setDataBits(8) // 数据位 + .setParity(0) // 校验位 + .setStopBits(1) // 停止位 + .setTimeout(500).setRetries(0); // 不重试 + AtomicReference errorInfo=new AtomicReference<>(""); + while (IsConnected==false) + { + mw.init(param, new ModbusCallback() { + @Override + public void onSuccess(com.serotonin.modbus4j.ModbusMaster modbusMaster) { + IsConnected=true; + MessageLog.ShowInfo("Modbus RTU 连接成功" ); + } + @Override + public void onFailure(Throwable tr) { + IsConnected = false; + errorInfo.set(tr.getMessage()); + MessageLog.ShowInfo("Modbus RTU 连接失败" ); + } + @Override + public void onFinally() { + + } + }); + if(!IsReconnection)break; + if(IsConnected==false) Thread.sleep(5000); + } + if(IsConnected)return OperateResult.CreateSuccess(); + else return OperateResult.CreateFailed(errorInfo.get()); + }catch(Exception ex){ + return OperateResult.CreateFailed(ex); + } + } + + @Override + public boolean getConnected() { + return IsConnected; + } + + public OperateResultT Read(String address, int length){ +// if(!getConnected()){ return OperateResultT.CreateFailedT("设备未连接");} + AtomicReference>resultValue=new AtomicReference>(); + try{ + String typeName= resultValue.get().Content.getClass().getCanonicalName(); + switch(typeName){ + case "java.lang.String": + resultValue.set((OperateResultT)ReadString(address,length)); + break; + case "java.lang.Byte": + resultValue.set((OperateResultT)ReadByte(address,1)); + break; + case "java.lang.Integer": + resultValue.set((OperateResultT)ReadInt(address)); + break; + case "java.lang.Float": + resultValue.set((OperateResultT)ReadFloat(address)); + break; + case "java.lang.Short": + resultValue.set((OperateResultT)ReadShort(address)); + break; + case "java.lang.Boolean": + resultValue.set((OperateResultT)ReadBool(address)); + break; + case "int[]": + resultValue.set((OperateResultT)ReadInt(address,length)); + break; + case "float[]": + resultValue.set((OperateResultT)ReadFloat(address,length)); + break; + case "short[]": + resultValue.set((OperateResultT)ReadShort(address,length)); + break; + case "boolean[]": + resultValue.set((OperateResultT)ReadBool(address,length)); + break; + default: + resultValue.set(OperateResultT.CreateFailedT("不匹配的数据类型:"+typeName)); + break; + } + }catch(Exception ex){ + resultValue.set(OperateResultT.CreateFailedT(ex)); + } +// if(result!=null)result.Run(resultValue.get()); + return resultValue.get(); + } + + public OperateResultT Read(String address){ +// if(!getConnected()){ return OperateResultT.CreateFailedT("设备未连接");} + AtomicReference>resultValue=new AtomicReference<>(); + resultValue.set(Read(address,1)); + return resultValue.get(); + } + public OperateResult Write(String address,T value) { + if(!getConnected()){ return OperateResult.CreateFailed("设备未连接");} + AtomicReferenceresultValue=new AtomicReference<>(); + try{ + String typeName= value.getClass().getCanonicalName(); + switch(typeName){ + case "java.lang.String": + resultValue.set(WriteString(address,value.toString(),SlaveId)); + break; + case "java.lang.Integer": + resultValue.set(WriteInt(address,Integer.parseInt(value.toString()))); + break; + case "java.lang.Float": + resultValue.set(WriteFloat(address,Float.parseFloat(value.toString()))); + break; + case "java.lang.Short": + resultValue.set(WriteShort(address,Short.parseShort(value.toString()))); + break; + case "java.lang.Boolean": + resultValue.set(WriteBool(address,Boolean.parseBoolean(value.toString()))); + break; + case "int[]": + resultValue.set(WriteInt(address,(int[])value)); + break; + case "float[]": + resultValue.set(WriteFloat(address,(float[])value)); + break; + case "short[]": + resultValue.set(WriteShort(address,(short[])value)); + break; + case "boolean[]": + resultValue.set(WriteBool(address,(boolean[])value)); + break; + default: + resultValue.set(OperateResult.CreateFailed("不匹配的数据类型:"+typeName)); + break; + } + }catch(Exception ex){ + resultValue.set(OperateResult.CreateFailed(ex)); + } + return resultValue.get(); + } + + @Override + public OperateResultT ReadBool(String address, int length) { + if(address==null||address.isEmpty()){ return OperateResultT.CreateFailedT("无效的地址");} + if(!getConnected()){ return OperateResultT.CreateFailedT("设备未连接");} + AtomicReference>resultValue=new AtomicReference<>(); + new ExceptionServer(address, length, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + ReadCoilsResponse res = mw.syncReadCoil(SlaveId, add, length); + boolean[] data = res.getBooleanData(); + boolean[] result = Arrays.copyOfRange(data, 0, length); + resultValue.set(OperateResultT.CreateSuccess(result)); + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResultT.CreateFailedT(address+",读取异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResultT ReadBool(String address) { + if(address==null||address.isEmpty()){ return OperateResultT.CreateFailedT("无效的地址");} + if(!getConnected()){ return OperateResultT.CreateFailedT("设备未连接");} + AtomicReference>resultValue=new AtomicReference<>(); + ReadBool(address,1).OnSource((s)->{ + resultValue.set(OperateResultT.CreateSuccess(s.Content[0])); + }).OnFailed(s->{ + resultValue.set(OperateResultT.CreateFailedT(s.message)); + }); + return resultValue.get(); + } + + @Override + public OperateResultT ReadInputCoil(String address, int length) { + if(address==null||address.isEmpty()){ return OperateResultT.CreateFailedT("无效的地址");} + if(!getConnected()){ return OperateResultT.CreateFailedT("设备未连接");} + AtomicReference>resultValue=new AtomicReference<>(); + new ExceptionServer(address, length, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + ReadDiscreteInputsResponse res = mw.syncReadDiscreteInput(SlaveId, add, length); + boolean[] data = res.getBooleanData(); + boolean[] result = Arrays.copyOfRange(data, 0, length); + resultValue.set(OperateResultT.CreateSuccess(result)); + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResultT.CreateFailedT(address+",读取异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResultT ReadInputCoil(String address) { + if(address==null||address.isEmpty()){ return OperateResultT.CreateFailedT("无效的地址");} + if(!getConnected()){ return OperateResultT.CreateFailedT("设备未连接");} + AtomicReference>resultValue=new AtomicReference<>(); + ReadInputCoil(address,1).OnSource((s)->{ + resultValue.set(OperateResultT.CreateSuccess(s.Content[0])); + }).OnFailed(s->{ + resultValue.set(OperateResultT.CreateFailedT(s.message)); + }); + return resultValue.get(); + } + + @Override + public OperateResultT ReadShort(String address, int length) { + if(address==null||address.isEmpty()){ return OperateResultT.CreateFailedT("无效的地址");} + if(!getConnected()){ return OperateResultT.CreateFailedT("设备未连接");} + AtomicReference>resultValue=new AtomicReference<>(); + new ExceptionServer(address, length, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + ReadHoldingRegistersResponse res = mw.syncReadHoldingRegisters(SlaveId, add, length); + short[] data = res.getShortData(); + if (data.length == length) { + resultValue.set(OperateResultT.CreateSuccess(data)); + } + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResultT.CreateFailedT(address+",读取异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResultT ReadShort(String address) { + if(address==null||address.isEmpty()){ return OperateResultT.CreateFailedT("无效的地址");} + if(!getConnected()){ return OperateResultT.CreateFailedT("设备未连接");} + AtomicReference>resultValue=new AtomicReference<>(); + ReadShort(address,1).OnSource((s)->{ + resultValue.set(OperateResultT.CreateSuccess(s.Content[0])); + }).OnFailed(s->{ + resultValue.set(OperateResultT.CreateFailedT(s.message)); + }); + return resultValue.get(); + } + @Override + public OperateResultT ReadInt(String address, int length) { + if(address==null||address.isEmpty()){ return OperateResultT.CreateFailedT("无效的地址");} + if(!getConnected()){ return OperateResultT.CreateFailedT("设备未连接");} + AtomicReference>resultValue=new AtomicReference<>(); + new ExceptionServer(address, length, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + ReadHoldingRegistersResponse res = mw.syncReadHoldingRegisters(SlaveId, add, length * 2); + int[] tempValues= IntLib.ToInts(res.getData(),ReadDataFormat); + if(tempValues.length==length){ + resultValue.set(OperateResultT.CreateSuccess(tempValues)); + }else{ + resultValue.set(OperateResultT.CreateFailedT(address+",读取失败,返回长度和实际读取长度不匹配")); + } + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResultT.CreateFailedT(address+",读取异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResultT ReadInt(String address) { + if(address==null||address.isEmpty()){ return OperateResultT.CreateFailedT("无效的地址");} + if(!getConnected()){ return OperateResultT.CreateFailedT("设备未连接");} + AtomicReference>resultValue=new AtomicReference<>(); + ReadInt(address,1).OnSource((s)->{ + resultValue.set(OperateResultT.CreateSuccess(s.Content[0])); + }).OnFailed(s->{ + resultValue.set(OperateResultT.CreateFailedT(s.message)); + }); + return resultValue.get(); + } + + @Override + public OperateResultT ReadByte(String address, int length) { + if(address==null||address.isEmpty()){ return OperateResultT.CreateFailedT("无效的地址");} + if(!getConnected()){ return OperateResultT.CreateFailedT("设备未连接");} + AtomicReference>resultValue=new AtomicReference<>(); + new ExceptionServer(address, length, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + int tempLength=length; + if (length%2!=0){ + tempLength++; + } + ReadHoldingRegistersResponse res = mw.syncReadHoldingRegisters(SlaveId, add, tempLength ); + byte[] data = res.getData(); + if(data.length==tempLength){ + byte[] result = Arrays.copyOfRange(data, 0, length); + resultValue.set(OperateResultT.CreateSuccess(result)); + }else{ + resultValue.set(OperateResultT.CreateFailedT(address+",读取失败,返回长度和实际读取长度不匹配")); + } + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResultT.CreateFailedT(address+",读取异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResultT ReadString(String address, int length) { + if(address==null||address.isEmpty()){ return OperateResultT.CreateFailedT("无效的地址");} + if(!getConnected()){ return OperateResultT.CreateFailedT("设备未连接");} + AtomicReference>resultValue=new AtomicReference<>(); + new ExceptionServer(address, length, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + ReadHoldingRegistersResponse res = mw.syncReadHoldingRegisters(SlaveId, add, length); + byte[] data = res.getData(); + try { + if (data.length ==length*2) { + resultValue.set(OperateResultT.CreateSuccess(new String(data, "UTF-8").trim())); + } + } catch (UnsupportedEncodingException ex) { + resultValue.set(OperateResultT.CreateFailedT(address+",读取失败,字符串解析失败:"+ex.toString())); + } + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResultT.CreateFailedT(address+",读取异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResultT ReadFloat(String address, int length) { + if(address==null||address.isEmpty()){ return OperateResultT.CreateFailedT("无效的地址");} + if(!getConnected()){ return OperateResultT.CreateFailedT("设备未连接");} + AtomicReference>resultValue=new AtomicReference<>(); + new ExceptionServer(address, length, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + ReadHoldingRegistersResponse res = mw.syncReadHoldingRegisters(SlaveId, add, length*2); + float[] tempValues = FloatLib.ToFloats(res.getData(),ReadDataFormat); + if (tempValues.length == length) { + resultValue.set(OperateResultT.CreateSuccess(tempValues)); + }else{ + resultValue.set(OperateResultT.CreateFailedT(address+",读取失败,返回长度和实际读取长度不匹配")); + } + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResultT.CreateFailedT(address+",读取异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResultT ReadFloat(String address) { + if(address==null||address.isEmpty()){ return OperateResultT.CreateFailedT("无效的地址");} + if(!getConnected()){ return OperateResultT.CreateFailedT("设备未连接");} + AtomicReference>resultValue=new AtomicReference<>(); + ReadFloat(address,1).OnSource((s)->{ + resultValue.set(OperateResultT.CreateSuccess(s.Content[0])); + }).OnFailed(s->{ + resultValue.set(OperateResultT.CreateFailedT(s.message)); + }); + return resultValue.get(); + } + + @Override + public OperateResult WriteBool(String address, boolean value) { + if(address==null||address.isEmpty()){ return OperateResult.CreateFailed("无效的地址");} + if(!getConnected()){ return OperateResult.CreateFailed("设备未连接");} + AtomicReferenceresultValue=new AtomicReference<>(); + new ExceptionServer(address, 1, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + mw.syncWriteCoil(SlaveId, add, value); + resultValue.set(OperateResult.CreateSuccess()); + } + @Override + public void onFailure(String error){ + resultValue.set(OperateResult.CreateFailed(address+",写入异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResult WriteBool(String address, boolean[] value) { + if(address==null||address.isEmpty()){ return OperateResult.CreateFailed("无效的地址");} + if(!getConnected()){ return OperateResult.CreateFailed("设备未连接");} + AtomicReferenceresultValue=new AtomicReference<>(); + new ExceptionServer(address, 1, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + mw.syncWriteCoils(SlaveId, add, value); + resultValue.set(OperateResult.CreateSuccess()); + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResult.CreateFailed(address+",写入异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResult WriteBool(String address, boolean[] value, int slaveId) { + if(address==null||address.isEmpty()){ return OperateResult.CreateFailed("无效的地址");} + if(!getConnected()){ return OperateResult.CreateFailed("设备未连接");} + AtomicReferenceresultValue=new AtomicReference<>(); + new ExceptionServer(address, 1, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + mw.syncWriteCoils(slaveId, add, value); + resultValue.set(OperateResult.CreateSuccess()); + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResult.CreateFailed(address+",写入异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResult WriteShort(String address, short value) { + if(address==null||address.isEmpty()){ return OperateResult.CreateFailed("无效的地址");} + if(!getConnected()){ return OperateResult.CreateFailed("设备未连接");} + return WriteShort(address, new short[]{value}); + } + + @Override + public OperateResult WriteShort(String address, short[] value) { + if(address==null||address.isEmpty()){ return OperateResult.CreateFailed("无效的地址");} + if(!getConnected()){ return OperateResult.CreateFailed("设备未连接");} + AtomicReferenceresultValue=new AtomicReference<>(); + new ExceptionServer(address, 1, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + mw.syncWriteRegisters(SlaveId, add, value); + resultValue.set(OperateResult.CreateSuccess()); + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResult.CreateFailed(address+",写入异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResult WriteShort(String address, short[] value, int slaveId) { + if(address==null||address.isEmpty()){ return OperateResult.CreateFailed("无效的地址");} + if(!getConnected()){ return OperateResult.CreateFailed("设备未连接");} + AtomicReferenceresultValue=new AtomicReference<>(); + new ExceptionServer(address, 1, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + mw.syncWriteRegisters(slaveId, add, value); + resultValue.set(OperateResult.CreateSuccess()); + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResult.CreateFailed(address+",写入异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResult WriteInt(String address, int value) { + if(address==null||address.isEmpty()){ return OperateResult.CreateFailed("无效的地址");} + if(!getConnected()){ return OperateResult.CreateFailed("设备未连接");} + return WriteInt(address, new int[]{value}); + } + + @Override + public OperateResult WriteInt(String address, int[] value) { + if(address==null||address.isEmpty()){ return OperateResult.CreateFailed("无效的地址");} + if(!getConnected()){ return OperateResult.CreateFailed("设备未连接");} + AtomicReferenceresultValue=new AtomicReference<>(); + new ExceptionServer(address, 1, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + short[] send=ShortLib.ToShorts(value,WriteDataFormat); + mw.syncWriteRegisters(SlaveId, add,send); + resultValue.set(OperateResult.CreateSuccess()); + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResult.CreateFailed(address+",写入异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResult WriteInt(String address, int[] value, int slaveId) { + if(address==null||address.isEmpty()){ return OperateResult.CreateFailed("无效的地址");} + if(!getConnected()){ return OperateResult.CreateFailed("设备未连接");} + AtomicReferenceresultValue=new AtomicReference<>(); + new ExceptionServer(address, 1, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + short[] send=ShortLib.ToShorts(value,WriteDataFormat); + mw. syncWriteRegisters(slaveId, add,send); + resultValue.set(OperateResult.CreateSuccess()); + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResult.CreateFailed(address+",写入异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResult WriteString(String address, String value, int slaveId) { + if(address==null||address.isEmpty()){ return OperateResult.CreateFailed("无效的地址");} + if(!getConnected()){ return OperateResult.CreateFailed("设备未连接");} + AtomicReferenceresultValue=new AtomicReference<>(); + new ExceptionServer(address, 1, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + byte[] bytes= value.getBytes(); + short[] send =ByteToShort(bytes); + mw.syncWriteRegisters(slaveId, add, send); + resultValue.set(OperateResult.CreateSuccess()); + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResult.CreateFailed(address+",写入异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResult WriteFloat(String address, float value) { + if(address==null||address.isEmpty()){ return OperateResult.CreateFailed("无效的地址");} + if(!getConnected()){ return OperateResult.CreateFailed("设备未连接");} + return WriteFloat(address, new float[]{value}); + } + + @Override + public OperateResult WriteFloat(String address, float[] value) { + if(address==null||address.isEmpty()){ return OperateResult.CreateFailed("无效的地址");} + if(!getConnected()){ return OperateResult.CreateFailed("设备未连接");} + AtomicReferenceresultValue=new AtomicReference<>(); + new ExceptionServer(address, 1, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + short[] send=ShortLib.ToShorts(value,WriteDataFormat); + mw.syncWriteRegisters(SlaveId, add, send); + resultValue.set(OperateResult.CreateSuccess()); + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResult.CreateFailed(address+",写入异常:"+error)); + } + }); + return resultValue.get(); + } + + @Override + public OperateResult WriteFloat(String address, float[] value, int slaveId) { + if(address==null||address.isEmpty()){ return OperateResult.CreateFailed("无效的地址");} + if(!getConnected()){ return OperateResult.CreateFailed("设备未连接");} + AtomicReferenceresultValue=new AtomicReference<>(); + new ExceptionServer(address, 1, new IExceptionHandling() { + @Override + public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { + short[] send=ShortLib.ToShorts(value,WriteDataFormat); + mw.syncWriteRegisters(slaveId, add, send); + resultValue.set(OperateResult.CreateSuccess()); + } + + @Override + public void onFailure(String error){ + resultValue.set(OperateResult.CreateFailed(address+",写入异常:"+error)); + } + }); + return resultValue.get(); + } + +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Communication/Siemens/CommHelper.java b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Siemens/CommHelper.java new file mode 100644 index 00000000..74c417c9 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Siemens/CommHelper.java @@ -0,0 +1,157 @@ +package com.bonait.bnframework.HBL.Communication.Siemens; + +import com.bonait.bnframework.HBL.DataUtil.Convert; +import com.bonait.bnframework.HBL.Interface.IRun; +import com.bonait.bnframework.HBL.Logs.MessageLog; +import com.bonait.bnframework.HBL.Result.OperateResult; +import com.bonait.bnframework.HBL.Result.OperateResultT; +import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType; + +public class CommHelper { + + private static CommHelper mInstance; //实例变量设置私有,防止直接通过类名访问 + + private CommHelper() { //默认构造函数私有,防止类外直接new创建对象 + } + + public static synchronized CommHelper get() { //静态同步方法作为唯一的实例对象获取方式 + if (mInstance == null) { + mInstance = new CommHelper(); + } + return mInstance; + } + private String IPAddress="127.0.0.1"; + public boolean IsConnected(){ + return siemens.IsConnected; + } + public IRun ConnectOk; + + public SiemensHelper siemens=new SiemensHelper(EPlcType.S200_SMART, IPAddress); + + public void Connect(){ + new Thread(new Runnable() { + @Override + public void run() { + MessageLog.ShowInfo("开始连接PLC"); + int tempFlag=0; + while (!siemens.checkConnected()){ + try{ + tempFlag++; + siemens=new SiemensHelper(EPlcType.S200_SMART, IPAddress); + siemens.connect(); + siemens.Delay(1000); + }catch (Exception e){ + if(tempFlag==1)MessageLog.ShowInfo("PLC连接失败:"+e.getMessage()); + siemens.Delay(1000); + } + } + if(ConnectOk!=null)ConnectOk.Run(); + siemens.IsConnected=true; + MessageLog.ShowInfo("PLC连接成功"); + } + }).start(); + } + + + + public void writePLC(String add,Object value){ + if(!IsConnected()) { + MessageLog.ShowInfo(add+":写入数据失败,连接已断开"); + return; + } + if(value==null) { + MessageLog.ShowInfo("writePLC:写入值为空"); + return; + } + try{ + if(add.toUpperCase().contains("VD")){ + Float tempVD= Float.parseFloat(value.toString()); + siemens.WriteFloat32(add,tempVD); + } + else if (add.toUpperCase().contains("VW")){ + Integer tempVW= Integer.parseInt(value.toString()); + siemens.WriteUInt16(add,tempVW); + } + else if (add.toUpperCase().contains("V")){ + Boolean tempV= Boolean.parseBoolean(value.toString()); + siemens.WriteBoolean(add,tempV); + } + }catch (Exception e){ + MessageLog.ShowInfo("writePLC:写入失败,"+e.getMessage()); + } + + } + + public Object readPLC(String add){ + try{ + if(add.toUpperCase().contains("VD")){ + return siemens.ReadFloat32(add); + } + else if (add.toUpperCase().contains("VW")||add.toUpperCase().contains("IW")||add.toUpperCase().contains("QW")){ + return siemens.ReadUInt16(add); + } + else if (add.toUpperCase().contains("V")){ + return siemens.ReadBoolean(add); + } + }catch (Exception e){ + MessageLog.ShowInfo("readPLC:读取失败,"+e.getMessage()); + } + return new Object(); + } + + public OperateResultT Read(String add){ + if(!IsConnected()) return OperateResultT.CreateFailedT(add+":读取数据失败,连接已断开"); + OperateResultT result = new OperateResultT<>(); + String typeName=result.Content.getClass() .getName(); + try{ + if(typeName.contains("Boolean")){ + return Convert.TryToGenericity(siemens.ReadBoolean(add)); + }else if(typeName.contains("Integer")){ + if(add.toUpperCase().contains("VD")){ + return Convert.TryToGenericity(siemens.ReadInt32(add)); + } + else if (add.toUpperCase().contains("VW")||add.toUpperCase().contains("IW")||add.toUpperCase().contains("QW")){ + return Convert.TryToGenericity(siemens.ReadUInt16(add)); + } + }else if(typeName.contains("Short")){ + return Convert.TryToGenericity(siemens.ReadInt16(add)); + }else if(typeName.contains("Float")){ + return Convert.TryToGenericity(siemens.ReadFloat32(add)); + }else{ + return OperateResultT.CreateFailedT(typeName+" 暂不支持的数据类型"); + } + }catch (Exception e){ + return OperateResultT.CreateFailedT(e); + } + return result; + } + + public OperateResult Write(String add, T value){ + if(!IsConnected()) return OperateResult.CreateFailed(add+":读取数据失败,连接已断开"); + if(value ==null) return OperateResult.CreateFailed(add+":写入值无效"); + String typeName=value.getClass() .getName(); + try{ + + if(typeName.contains("Boolean")){ + Convert.TryToGenericity(value).OnSource(s->{ siemens.WriteBoolean(add,s.Content);}); + }else if(typeName.contains("Integer")){ + if(add.toUpperCase().contains("VD")){ + Convert.TryToGenericity(value).OnSource(s->{ siemens.WriteInt32(add,s.Content);}); + } + else if (add.toUpperCase().contains("VW")){ + Convert.TryToGenericity(value).OnSource(s->{ siemens.WriteUInt16(add,s.Content);}); + } + }else if(typeName.contains("Short")){ + Convert.TryToGenericity(value).OnSource(s->{ siemens.WriteInt16(add,s.Content);}); + }else if(typeName.contains("Float")){ + Convert.TryToGenericity(value).OnSource(s->{ siemens.WriteFloat32(add,s.Content);}); + }else{ + return OperateResult.CreateFailed(typeName+" 暂不支持的数据类型"); + } + return OperateResult.CreateSuccess(); + }catch (Exception e){ + return OperateResult.CreateFailed(e); + } + } + +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Communication/Siemens/SiemensHelper.java b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Siemens/SiemensHelper.java new file mode 100644 index 00000000..4db60e71 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Siemens/SiemensHelper.java @@ -0,0 +1,360 @@ +package com.bonait.bnframework.HBL.Communication.Siemens; + +import android.util.Log; + +import com.bonait.bnframework.HBL.Logs.MessageLog; +import com.github.xingshuangs.iot.exceptions.SocketRuntimeException; +import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType; +import com.github.xingshuangs.iot.protocol.s7.model.DataItem; +import com.github.xingshuangs.iot.protocol.s7.service.S7PLC; +import com.github.xingshuangs.iot.protocol.s7.utils.AddressUtil; +import com.github.xingshuangs.iot.utils.FloatUtil; +import com.github.xingshuangs.iot.utils.IntegerUtil; +import com.github.xingshuangs.iot.utils.ShortUtil; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class SiemensHelper extends S7PLC { + public Boolean IsConnected=false; + + public boolean CancelWrite=false; + + + public void Delay(long millis){ + try{ + Thread.sleep(millis); + }catch(InterruptedException e){ + + } + } + + public boolean ReadBoolean(String address){ + boolean result=false; + while(true){ + try { + result=this.readBoolean(address); + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + this.close(); + IsConnected=false; + Delay(1000); + } + } + return result; + } + + public List ReadBoolean(String... address) { + List result=new ArrayList<>(); + while(true){ + try { + result=this.readBoolean(Arrays.asList(address)); + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + this.close(); + IsConnected=false; + Delay(1000); + } + } + return result; + } + + public short ReadInt16(String address) { + short result=0; + while(true){ + try { + DataItem dataItem = this.readS7Data(AddressUtil.parseByte(address, 2)); + result= ShortUtil.toInt16(dataItem.getData()); + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + this.close(); + IsConnected=false; + Delay(1000); + } + } + return result; + + } + + public List ReadInt16(String... address) { + List result=new ArrayList<>(); + while(true){ + try { + result=this.readInt16(Arrays.asList(address)); + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + this.close(); + IsConnected=false; + Delay(1000); + } + } + + return result; + } + + public int ReadUInt16(String address) { + int result=0; + while(true){ + try { + DataItem dataItem = this.readS7Data(AddressUtil.parseByte(address, 2)); + result= ShortUtil.toUInt16(dataItem.getData()); + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + this.close(); + IsConnected=false; + Delay(1000); + } + } + return result; + } + + public List ReadUInt16(String... address) { + List result=new ArrayList<>(); + while(true){ + try { + result=this.readUInt16(Arrays.asList(address)); + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + this.close(); + IsConnected=false; + Delay(1000); + } + } + return result; + } + + public int ReadInt32(String address) { + int result=0; + while(true){ + try { + DataItem dataItem = this.readS7Data(AddressUtil.parseByte(address, 4)); + result= IntegerUtil.toInt32(dataItem.getData()); + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + this.close(); + IsConnected=false; + Delay(1000); + } + } + return result; + } + + public List ReadInt32(String... address) { + List result=new ArrayList<>(); + while(true){ + try { + result=this.readInt32(Arrays.asList(address)); + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + this.close(); + IsConnected=false; + Delay(1000); + } + } + return result; + } + + public float ReadFloat32(String address) { + float result=0f; + while(true){ + try { + DataItem dataItem = this.readS7Data(AddressUtil.parseByte(address, 4)); + result= FloatUtil.toFloat32(dataItem.getData()); + + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + this.close(); + IsConnected=false; + Delay(1000); + } + } + return result; + } + + public List ReadFloat32(String... address) { + List result=new ArrayList<>(); + while(true){ + try { + result=this.readFloat32(Arrays.asList(address)); + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + this.close(); + IsConnected=false; + Delay(1000); + } + } + return result; + } + + public void WriteBoolean(String address, boolean data) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":写入数据失败,连接已断开"); + return; + } + while (true) { + try { + this.writeS7Data(AddressUtil.parseBit(address), DataItem.createReqByBoolean(data)); + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + this.close(); + IsConnected=false; + Delay(100); + if(CancelWrite)break; + } + catch (Exception e){ + MessageLog.ShowError("WriteBoolean 写入异常:"+e.toString()); + break; + } + } + } + + public void WriteUInt16(String address, int data) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":写入数据失败,连接已断开"); + return; + } + while (true) { + try { + this.writeByte(address, ShortUtil.toByteArray(data)); + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + this.close(); + IsConnected=false; + Delay(100); + if(CancelWrite)break; + } + catch (Exception e){ + MessageLog.ShowError("WriteUInt16 写入异常:"+e.toString()); + break; + } + } + } + + public void WriteInt16(String address, short data) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":写入数据失败,连接已断开"); + return; + } + while (true) { + try { + Log.e("info","准备写入数据:"+data); + this.writeByte(address, ShortUtil.toByteArray(data)); + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + Log.e("socketException","写入:"+data+"失败"); + this.close(); + IsConnected=false; + Delay(100); + if(CancelWrite)break; + } + catch (Exception e){ + MessageLog.ShowError("WriteInt16 写入异常:"+e.toString()); + break; + } + } + } + + public void WriteUInt32(String address, long data) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":写入数据失败,连接已断开"); + return; + } + while (true) { + try { + this.writeByte(address, IntegerUtil.toByteArray(data)); + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + this.close(); + IsConnected=false; + Delay(100); + if(CancelWrite)break; + } + catch (Exception e){ + MessageLog.ShowError("WriteUInt32 写入异常:"+e.toString()); + break; + } + } + } + + public void WriteInt32(String address, int data) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":写入数据失败,连接已断开"); + return; + } + while (true) { + try { + this.writeByte(address, IntegerUtil.toByteArray(data)); + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + this.close(); + IsConnected=false; + Delay(100); + if(CancelWrite)break; + } + catch (Exception e){ + MessageLog.ShowError("WriteInt32 写入异常:"+e.toString()); + break; + } + } + } + + public void WriteFloat32(String address, float data) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":写入数据失败,连接已断开"); + return; + } + while (true) { + try { + this.writeByte(address, FloatUtil.toByteArray(data)); + IsConnected=true; + break; + } + catch(SocketRuntimeException ex){ + this.close(); + IsConnected=false; + Delay(100); + if(CancelWrite)break; + } + catch (Exception e){ + MessageLog.ShowError("WriteFloat32 写入异常:"+e.toString()); + break; + } + } + } + + public SiemensHelper(EPlcType PlcType, String ip){ + super(PlcType, ip); + } + +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/CustomView/ShadowContainer.java b/app/src/main/java/com/bonait/bnframework/HBL/CustomView/ShadowContainer.java new file mode 100644 index 00000000..c6c885be --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/CustomView/ShadowContainer.java @@ -0,0 +1,213 @@ +package com.bonait.bnframework.HBL.CustomView; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.RectF; +import android.os.Build; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewGroup; + +import com.bonait.bnframework.R; + + +/** + * 阴影容器 + * 需要在 res->values->attrs.xml中添加以下内容 + * + * + * + * + * + * + * + * + * + * Reference: https://github.com/cjlemon/Shadow + */ +public class ShadowContainer extends ViewGroup { + + private final float deltaLength; + private final float cornerRadius; + private final Paint mShadowPaint; + private boolean drawShadow; + + public ShadowContainer(Context context) { + this(context, null); + } + + public ShadowContainer(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public ShadowContainer(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ShadowContainer); + int shadowColor = a.getColor(R.styleable.ShadowContainer_containerShadowColor, Color.RED); + float shadowRadius = a.getDimension(R.styleable.ShadowContainer_containerShadowRadius, 0); + deltaLength = a.getDimension(R.styleable.ShadowContainer_containerDeltaLength, 0); + cornerRadius = a.getDimension(R.styleable.ShadowContainer_containerCornerRadius, 0); + float dx = a.getDimension(R.styleable.ShadowContainer_deltaX, 0); + float dy = a.getDimension(R.styleable.ShadowContainer_deltaY, 0); + drawShadow = a.getBoolean(R.styleable.ShadowContainer_enable, true); + a.recycle(); + mShadowPaint = new Paint(); + mShadowPaint.setStyle(Paint.Style.FILL); + mShadowPaint.setAntiAlias(true); + mShadowPaint.setColor(shadowColor); + mShadowPaint.setShadowLayer(shadowRadius, dx, dy, shadowColor); + } + + @Override + protected void dispatchDraw(Canvas canvas) { + if (drawShadow) { + /* + setShadowLayer()/setMaskFilter is not support hardware acceleration, so using LAYER_TYPE_SOFTWARE, but software layers isn't always good. + LAYER_TYPE_SOFTWARE: software layers should be avoided when the affected view tree updates often. + */ + if (getLayerType() != LAYER_TYPE_SOFTWARE) { + setLayerType(LAYER_TYPE_SOFTWARE, null); + } + View child = getChildAt(0); + int left = child.getLeft(); + int top = child.getTop(); + int right = child.getRight(); + int bottom = child.getBottom(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + canvas.drawRoundRect(left, top, right, bottom, cornerRadius, cornerRadius, mShadowPaint); + } else { + Path drawablePath = new Path(); + drawablePath.moveTo(left + cornerRadius, top); + drawablePath.arcTo(new RectF(left, top, left + 2 * cornerRadius, top + 2 * cornerRadius), -90, -90, false); + drawablePath.lineTo(left, bottom - cornerRadius); + drawablePath.arcTo(new RectF(left, bottom - 2 * cornerRadius, left + 2 * cornerRadius, bottom), 180, -90, false); + drawablePath.lineTo(right - cornerRadius, bottom); + drawablePath.arcTo(new RectF(right - 2 * cornerRadius, bottom - 2 * cornerRadius, right, bottom), 90, -90, false); + drawablePath.lineTo(right, top + cornerRadius); + drawablePath.arcTo(new RectF(right - 2 * cornerRadius, top, right, top + 2 * cornerRadius), 0, -90, false); + drawablePath.close(); + canvas.drawPath(drawablePath, mShadowPaint); + } + } + super.dispatchDraw(canvas); + } + + /** + * setMeasuredDimension(): store the modified width and modified height. + * + * @param widthMeasureSpec the original width + * @param heightMeasureSpec the original height + */ + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + if (getChildCount() != 1) { + throw new IllegalStateException("Child View can have only one!!!"); + } + int measuredWidth = getMeasuredWidth(); + int measuredHeight = getMeasuredHeight(); + int widthMode = MeasureSpec.getMode(widthMeasureSpec); + int heightMode = MeasureSpec.getMode(heightMeasureSpec); + View child = getChildAt(0); + MarginLayoutParams layoutParams = (MarginLayoutParams) child.getLayoutParams(); + int childBottomMargin = (int) (Math.max(deltaLength, layoutParams.bottomMargin) + 1); + int childLeftMargin = (int) (Math.max(deltaLength, layoutParams.leftMargin) + 1); + int childRightMargin = (int) (Math.max(deltaLength, layoutParams.rightMargin) + 1); + int childTopMargin = (int) (Math.max(deltaLength, layoutParams.topMargin) + 1); + int widthMeasureSpecMode; + int widthMeasureSpecSize; + int heightMeasureSpecMode; + int heightMeasureSpecSize; + if (widthMode == MeasureSpec.UNSPECIFIED) { + widthMeasureSpecMode = MeasureSpec.UNSPECIFIED; + widthMeasureSpecSize = MeasureSpec.getSize(widthMeasureSpec); + } else { + if (layoutParams.width == MarginLayoutParams.MATCH_PARENT) { + widthMeasureSpecMode = MeasureSpec.EXACTLY; + widthMeasureSpecSize = measuredWidth - childLeftMargin - childRightMargin; + } else if (MarginLayoutParams.WRAP_CONTENT == layoutParams.width) { + widthMeasureSpecMode = MeasureSpec.AT_MOST; + widthMeasureSpecSize = measuredWidth - childLeftMargin - childRightMargin; + } else { + widthMeasureSpecMode = MeasureSpec.EXACTLY; + widthMeasureSpecSize = layoutParams.width; + } + } + if (heightMode == MeasureSpec.UNSPECIFIED) { + heightMeasureSpecMode = MeasureSpec.UNSPECIFIED; + heightMeasureSpecSize = MeasureSpec.getSize(heightMeasureSpec); + } else { + if (layoutParams.height == MarginLayoutParams.MATCH_PARENT) { + heightMeasureSpecMode = MeasureSpec.EXACTLY; + heightMeasureSpecSize = measuredHeight - childBottomMargin - childTopMargin; + } else if (MarginLayoutParams.WRAP_CONTENT == layoutParams.height) { + heightMeasureSpecMode = MeasureSpec.AT_MOST; + heightMeasureSpecSize = measuredHeight - childBottomMargin - childTopMargin; + } else { + heightMeasureSpecMode = MeasureSpec.EXACTLY; + heightMeasureSpecSize = layoutParams.height; + } + } + measureChild(child, MeasureSpec.makeMeasureSpec(widthMeasureSpecSize, widthMeasureSpecMode), MeasureSpec.makeMeasureSpec(heightMeasureSpecSize, heightMeasureSpecMode)); + int parentWidthMeasureSpec = MeasureSpec.getMode(widthMeasureSpec); + int parentHeightMeasureSpec = MeasureSpec.getMode(heightMeasureSpec); + int height = measuredHeight; + int width = measuredWidth; + int childHeight = child.getMeasuredHeight(); + int childWidth = child.getMeasuredWidth(); + if (parentHeightMeasureSpec == MeasureSpec.AT_MOST) { + height = childHeight + childTopMargin + childBottomMargin; + } + if (parentWidthMeasureSpec == MeasureSpec.AT_MOST) { + width = childWidth + childRightMargin + childLeftMargin; + } + if (width < childWidth + 2 * deltaLength) { + width = (int) (childWidth + 2 * deltaLength); + } + if (height < childHeight + 2 * deltaLength) { + height = (int) (childHeight + 2 * deltaLength); + } + if (height != measuredHeight || width != measuredWidth) { + setMeasuredDimension(width, height); + } + } + + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + View child = getChildAt(0); + int measuredWidth = getMeasuredWidth(); + int measuredHeight = getMeasuredHeight(); + int childMeasureWidth = child.getMeasuredWidth(); + int childMeasureHeight = child.getMeasuredHeight(); + child.layout((measuredWidth - childMeasureWidth) / 2, (measuredHeight - childMeasureHeight) / 2, (measuredWidth + childMeasureWidth) / 2, (measuredHeight + childMeasureHeight) / 2); + } + + @Override + protected LayoutParams generateDefaultLayoutParams() { + return new MarginLayoutParams(MarginLayoutParams.WRAP_CONTENT, MarginLayoutParams.WRAP_CONTENT); + } + + @Override + protected LayoutParams generateLayoutParams(LayoutParams p) { + return new MarginLayoutParams(p); + } + + @Override + public LayoutParams generateLayoutParams(AttributeSet attrs) { + return new MarginLayoutParams(getContext(), attrs); + } + + public void setDrawShadow(boolean drawShadow) { + if (this.drawShadow == drawShadow) { + return; + } + this.drawShadow = drawShadow; + postInvalidate(); + } + +} + diff --git a/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/ByteLib.java b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/ByteLib.java new file mode 100644 index 00000000..42f0d3aa --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/ByteLib.java @@ -0,0 +1,81 @@ +package com.bonait.bnframework.HBL.DataUtil; + + +import com.bonait.bnframework.HBL.Enum.DataFormat; + +public class ByteLib { + + public static byte[] ToBytes(short value, DataFormat df) { + byte[] b = new byte[2]; + b[0]=(byte)((value>>8)&0xff); + b[1]=(byte)((value>>0)&0xff); + return new ByteTransDataFormat().ByteTransDataFormat2(b,df,0); + } + + public static byte[] ToBytes(short[] value,DataFormat df) { + byte[] b = new byte[value.length*2]; + for (int i = 0; i < value.length; i++) + { + b[i*2]=(byte)((value[i]>>8)&0xff); + b[i*2+1]=(byte)((value[i]>>0)&0xff); + } + return new ByteTransDataFormat().ByteTransDataFormat2(b,df,0); + } + + public static byte[] ToBytes(float value,DataFormat df) { + int tempValue = Float.floatToRawIntBits(value); + byte[] b = new byte[4]; + b[0]=(byte)((tempValue>>24)&0xff); + b[1]=(byte)((tempValue>>16)&0xff); + b[2]=(byte)((tempValue>>8)&0xff); + b[3]=(byte)((tempValue>>0)&0xff); + return new ByteTransDataFormat().ByteTransDataFormat4(b,df,0); + } + + public static byte[] ToBytes(float[] value,DataFormat df) { + byte[] b = new byte[value.length*4]; + for (int i=0;i>24)&0xff); + b[i*4+1]=(byte)((tempValue>>16)&0xff); + b[i*4+2]=(byte)((tempValue>>8)&0xff); + b[i*4+3]=(byte)((tempValue>>0)&0xff); + } + return new ByteTransDataFormat().ByteTransDataFormat4(b,df,0); + } + + public static byte[] ToBytes(int value,DataFormat df) { + byte[] b = new byte[4]; + b[0]=(byte)((value>>24)&0xff); + b[1]=(byte)((value>>16)&0xff); + b[2]=(byte)((value>>8)&0xff); + b[3]=(byte)((value>>0)&0xff); + return new ByteTransDataFormat().ByteTransDataFormat4(b,df,0); + } + + public static byte[] ToBytes(int[] value,DataFormat df) { + byte[] b = new byte[value.length*4]; + for (int i=0;i>24)&0xff); + b[i*4+1]=(byte)((value[i]>>16)&0xff); + b[i*4+2]=(byte)((value[i]>>8)&0xff); + b[i*4+3]=(byte)((value[i]>>0)&0xff); + } + return new ByteTransDataFormat().ByteTransDataFormat4(b,df,0); + } + + public static boolean GetBit(byte value,int offset) + { + if (offset > 8 || offset < 1) return false; + return (value & 1 << offset - 1) == 0 ? false : true; + } + + public static byte SetBit(byte value,int offset, boolean val) + { + if (offset > 8 || offset < 1) return value; + int ConvertValue = 1 << offset - 1; + return (byte)(val ? value | ConvertValue : value & ~ConvertValue); + } +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/ByteTransDataFormat.java b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/ByteTransDataFormat.java new file mode 100644 index 00000000..1f43c500 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/ByteTransDataFormat.java @@ -0,0 +1,51 @@ +package com.bonait.bnframework.HBL.DataUtil; + + +import com.bonait.bnframework.HBL.Enum.DataFormat; + +public class ByteTransDataFormat { + public byte[] ByteTransDataFormat2(byte[] data, DataFormat df, int offset ){ + if (offset+2<2) return new byte[2]; + byte[] numArray = new byte[2]; + if (df==DataFormat.ABCD||df==DataFormat.BADC){ + numArray[0] = data[offset+1]; + numArray[1] = data[offset]; + } + else { + numArray[0] = data[offset]; + numArray[1] = data[offset+1]; + } + return numArray; + } + + public byte[] ByteTransDataFormat4(byte[] data, DataFormat df,int offset ){ + if (offset+4<4) return new byte[4]; + byte[] numArray = new byte[4]; + if (df==DataFormat.ABCD){ + numArray[0] = data[offset+3]; + numArray[1] = data[offset+2]; + numArray[2] = data[offset+1]; + numArray[3] = data[offset]; + } + else if (df==DataFormat.BADC){ + numArray[0] = data[offset+2]; + numArray[1] = data[offset+3]; + numArray[2] = data[offset]; + numArray[3] = data[offset+1]; + } + else if(df==DataFormat.CDAB){ + numArray[0] = data[offset+1]; + numArray[1] = data[offset]; + numArray[2] = data[offset+3]; + numArray[3] = data[offset+2]; + } + else if(df==DataFormat.DCBA){ + numArray[0] = data[offset]; + numArray[1] = data[offset+1]; + numArray[2] = data[offset+2]; + numArray[3] = data[offset+3]; + } + return numArray; + } +} + diff --git a/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/Convert.java b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/Convert.java new file mode 100644 index 00000000..f21ce60a --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/Convert.java @@ -0,0 +1,107 @@ +package com.bonait.bnframework.HBL.DataUtil; + + +import com.bonait.bnframework.HBL.Result.OperateResultT; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public class Convert { + public static OperateResultT TryToBoolean(Object value){ + if(value==null) return OperateResultT.CreateFailedT("TryToBoolean:转换对象为空"); + try{ + return OperateResultT.CreateSuccess(Boolean.parseBoolean(value.toString())); + }catch (Exception e) { + return OperateResultT.CreateFailedT(e); + } + } + + public static OperateResultT TryToInt(Object value){ + if(value==null) return OperateResultT.CreateFailedT("TryToInt:转换对象为空"); + try{ + return OperateResultT.CreateSuccess(Integer.parseInt(value.toString())); + }catch (Exception e) { + return OperateResultT.CreateFailedT(e); + } + } + + public static OperateResultT TryToShort(Object value){ + if(value==null) return OperateResultT.CreateFailedT("TryToShort:转换对象为空"); + try{ + return OperateResultT.CreateSuccess(Short.parseShort(value.toString())); + }catch (Exception e) { + return OperateResultT.CreateFailedT(e); + } + } + + public static OperateResultT TryToFloat(Object value){ + if(value==null) return OperateResultT.CreateFailedT("TryToFloat:转换对象为空"); + try{ + return OperateResultT.CreateSuccess(Float.parseFloat(value.toString())); + }catch (Exception e) { + return OperateResultT.CreateFailedT(e); + } + } + + public static OperateResultT TryToGenericity( Object value){ + if(value==null) return OperateResultT.CreateFailedT("TryToGenericity:转换对象为空"); + try{ + return OperateResultT.CreateSuccess((T)value); + }catch (Exception e) { + return OperateResultT.CreateFailedT(e); + } + } + +// public static OperateResultT TryToNumber(Object value,Class type){ +// if(value==null) return OperateResultT.CreateFailedT("TryToGenericity:转换对象为空"); +// try{ +// String temp = value.toString(); +// if(type==Integer.TYPE){ +// return OperateResultT.CreateSuccess((T)Integer.valueOf(temp)); +// }else if (type==Short.TYPE){ +// return OperateResultT.CreateSuccess((T)Short.valueOf(temp)); +// }else if (type==Byte.TYPE){ +// return OperateResultT.CreateSuccess((T)Byte.valueOf(temp)); +// }else if (type==Float.TYPE){ +// return OperateResultT.CreateSuccess((T)Float.valueOf(temp)); +// }else if (type==Long.TYPE){ +// return OperateResultT.CreateSuccess((T)Long.valueOf(temp)); +// }else if (type==Double.TYPE){ +// return OperateResultT.CreateSuccess((T)Double.valueOf(temp)); +// }else if (type.getName().contains(Boolean.TYPE.getName())){ +// return OperateResultT.CreateSuccess((T)Boolean.valueOf(temp)); +// }else if (type.getName().contains(String.class.getName())){ +// return OperateResultT.CreateSuccess((T)temp); +// } +// return OperateResultT.CreateSuccess((T)value); +// }catch (Exception e) { +// return OperateResultT.CreateFailedT(e); +// } +// } + + public static OperateResultT fromJson(Object value, Class clazz) { + if(value==null) return OperateResultT.CreateFailedT("TryToBoolean:转换对象为空"); + try{ + Gson gson = new GsonBuilder().create(); + String temp = gson.toJson(value); + T arr = gson.fromJson(temp, clazz); + if(arr!=null)return OperateResultT.CreateSuccess( arr ); + else return OperateResultT.CreateFailedT("返回对象为空"); + }catch (Exception e) { + return OperateResultT.CreateFailedT(e); + } + } + + public static OperateResultT fromJson(String value, Class clazz) { + if(value==null||value.isEmpty()) return OperateResultT.CreateFailedT("TryToBoolean:转换对象为空"); + try{ + Gson gson = new GsonBuilder().create(); + T arr = gson.fromJson(value, clazz); + if(arr!=null)return OperateResultT.CreateSuccess( arr); + else return OperateResultT.CreateFailedT("返回对象为空"); + }catch (Exception e) { + return OperateResultT.CreateFailedT(e); + } + } + + +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/DataConvertLib.java b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/DataConvertLib.java new file mode 100644 index 00000000..2e4198fe --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/DataConvertLib.java @@ -0,0 +1,244 @@ +package com.bonait.bnframework.HBL.DataUtil; + + + + +import com.bonait.bnframework.HBL.Enum.DataFormat; + +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; + +public class DataConvertLib { + + /*** + * 字节数组转换成浮点数 + * @param ,需要转换的字节 + * @param ,转换的数据格式 + * @return + */ + public static Float BytesToFloat(byte[] buffers, DataFormat df) { + if (buffers.length == 4) { + byte[] bytes = new byte[4]; + if (df == DataFormat.ABCD) { + bytes[0] = buffers[3]; + bytes[1] = buffers[2]; + bytes[2] = buffers[1]; + bytes[3] = buffers[0]; + } else if (df == DataFormat.CDAB) { + bytes[0] = buffers[1]; + bytes[1] = buffers[0]; + bytes[2] = buffers[3]; + bytes[3] = buffers[2]; + } else if (df == DataFormat.BADC) { + bytes[0] = buffers[2]; + bytes[1] = buffers[3]; + bytes[2] = buffers[0]; + bytes[3] = buffers[1]; + } else if (df == DataFormat.DCBA) { + bytes[0] = buffers[0]; + bytes[1] = buffers[1]; + bytes[2] = buffers[2]; + bytes[3] = buffers[3]; + } + return ByteBuffer.wrap(bytes).getFloat(); + } + return 0.0f; + } + + /** + * 字节数组转换成整形 + * @param ,需要转换的字节数组 + * @param ,转换的数据格式 + * @return + */ + public static Integer BytesToInt(byte[] buffers, DataFormat df) { + if (buffers.length == 4) { + byte[] bytes = new byte[4]; + if (df == DataFormat.ABCD) { + bytes[0] = buffers[3]; + bytes[1] = buffers[2]; + bytes[2] = buffers[1]; + bytes[3] = buffers[0]; + } else if (df == DataFormat.CDAB) { + bytes[0] = buffers[1]; + bytes[1] = buffers[0]; + bytes[2] = buffers[3]; + bytes[3] = buffers[2]; + } else if (df == DataFormat.BADC) { + bytes[0] = buffers[2]; + bytes[1] = buffers[3]; + bytes[2] = buffers[0]; + bytes[3] = buffers[1]; + } else if (df == DataFormat.DCBA) { + bytes[0] = buffers[0]; + bytes[1] = buffers[1]; + bytes[2] = buffers[2]; + bytes[3] = buffers[3]; + } + return ByteBuffer.wrap(bytes).getInt(); + } + return 0; + } + + /** + * 32位整数转换成字节 + * @param ,number + * @return + */ + public static byte[] IntToByte(int number) { + int temp = number; + byte[] b = new byte[4]; + for (int i = 0; i < b.length; i++) { + b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位 + temp = temp >> 8; // 向右移8位 + } + return b; + } + + /** + * 32位整形转换成16位整数数组 + * @param ,value + * @return + */ + public static short[] IntToShorts(int value) { + short[] res = new short[2]; + int temp = value; + byte[] b = new byte[4]; + for (int i = 0; i < b.length; i++) { + b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位 + temp = temp >> 8; // 向右移8位 + } + for (int i = 0; i < res.length; i++) { + short s0 = (short) (b[i * 2] & 0xff);// 最低位 + short s1 = (short) (b[i * 2 + 1] & 0xff); + s1 <<= 8; + res[i] = (short) (s0 | s1); + } + return res; + } + + public static String GetString(short[] src, int start, int len) throws UnsupportedEncodingException { + short[] temp = new short[len]; + for (int i = 0; i < len; i++) { + temp[i] = src[i + start]; + } + byte[] bytesTemp = shorts2Bytes(temp); + for (int i = 0; i < bytesTemp.length; i++) { + byte b = bytesTemp[i]; + } + String str = new String(bytesTemp, "UTF-8"); + return str; + } + + public static short[] ByteToShort(byte[] bytes) { + + int len=bytes.length; + if (bytes.length%2!=0) len++; + byte[] tempBytes=new byte[len]; + short[] result = new short[len/2]; + for (int i=0;i> 8); + } + return byteValue; + } + + public static int GetAddress(String address) { + if (address == null) return -1; + if (address.length() > 0) { + address = address.trim(); + if (address.toUpperCase().contains("M") && address.length() >= 4) { + String[] res = address.substring(1).split("[.]"); + if (res != null && res.length == 2) { + try { + int firstAdd = Integer.parseInt(res[0]); + int endAdd = Integer.parseInt(res[1]); + if (endAdd >= 0 && endAdd <= 7) { + return (firstAdd * 8) + 320 + endAdd; + } + } catch (NumberFormatException e) { + return -1; + } + } + } else if (address.toUpperCase().contains("I") && address.length() >= 4) { + String[] res = address.substring(1).split("[.]"); + if (res != null && res.length == 2) { + try { + int firstAdd = Integer.parseInt(res[0]); + int endAdd = Integer.parseInt(res[1]); + if (endAdd >= 0 && endAdd <= 7) { + return (firstAdd * 8) + endAdd; + } + } catch (NumberFormatException e) { + return -1; + } + } + } else if ((address.toUpperCase().contains("VW") || address.toUpperCase().contains("VD")) && address.length() >= 3) { + String res = address.substring(2); + if (res != null) { + try { + int tempAdd = Integer.parseInt(res); + return (tempAdd / 2) + 100; + } catch (NumberFormatException e) { + return -1; + } + } + }else if (address.toUpperCase().contains("GI") &&address.length() >=3){ + String res = address.substring(2); + if (res != null) { + try { + return Integer.parseInt(res); + } catch (NumberFormatException e) { + return -1; + } + } + } + else { + try { + return Integer.parseInt(address); + } catch (NumberFormatException e) { + return -1; + } + } + } + return -1; + } + + + /** + * 获取布尔位地址信息 + * 列:M2.5 = getBitSingleAdd("M",2,5); + * + * @param Prefix 地址标头 + * @param startAdd 起始地址编号 + * @param num 要获取的第几位数量 + * @return + */ + public static String getBitSingleAdd(String Prefix, int startAdd, int num) { + if (num > 0) { + int FirstAdd = num / 8; + int EndAdd = num % 8; + if (EndAdd == 0) { + FirstAdd--; + EndAdd = 7; + } else { + EndAdd--; + } + return Prefix + FirstAdd + startAdd + "." + EndAdd; + } + return ""; + } + +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/DataType.java b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/DataType.java new file mode 100644 index 00000000..fcf2a57b --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/DataType.java @@ -0,0 +1,12 @@ +package com.bonait.bnframework.HBL.DataUtil; + +public class DataType { + public static final String STRING=""; + public static final byte BYTE=0; + public static final short SHORT=0; + public static final int INT=0; + public static final long LONG=0; + public static final float FLOAT=0f; + public static final double DOUBLE=0d; + public static final boolean BOOLEAN=false; +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/FloatLib.java b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/FloatLib.java new file mode 100644 index 00000000..2b1103bf --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/FloatLib.java @@ -0,0 +1,31 @@ +package com.bonait.bnframework.HBL.DataUtil; + + + + +import com.bonait.bnframework.HBL.Enum.DataFormat; + +import java.nio.ByteBuffer; + +public class FloatLib { + public static float ToFloat(byte[] bytes, DataFormat df) { + byte[] res= new ByteTransDataFormat().ByteTransDataFormat4(bytes,df,0); + return ByteBuffer.wrap(res).getFloat(); + } + + public static float[] ToFloats(byte[] bytes, DataFormat df) { + byte[] tempBytes=new byte[bytes.length]; + if (bytes.length%4!=0) + { + int offset=4-bytes.length%4; + tempBytes=new byte[bytes.length+offset]; + } + for (int i=0;i 32 || offset < 1) return false; + return (value & 1 << offset - 1) == 0 ? false : true; + } + + public static int SetBit(int value,int offset, boolean val) + { + if (offset > 32 || offset < 1) return value; + int ConvertValue =1 << offset - 1; + return val ? value | ConvertValue : value & ~ConvertValue; + } +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/NotifyPropVar.java b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/NotifyPropVar.java new file mode 100644 index 00000000..7eb4463c --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/NotifyPropVar.java @@ -0,0 +1,37 @@ +package com.bonait.bnframework.HBL.DataUtil; + + + +import com.bonait.bnframework.HBL.Interface.IRunT; + +import java.io.Serializable; +import java.util.LinkedHashMap; + +public class NotifyPropVar { + + public NotifyPropVar(T defaultValue){ + _value=defaultValue; + } + public IRunT ChangeNotify; + + private boolean IsFirst=false; + private LinkedHashMap> changedNotifys=new LinkedHashMap<>(); + + public void Register(String key,IRunT notify){ +// if(changedNotifys.containsKey(key))changedNotifys.remove(key); + changedNotifys.put(key,notify); + } + + private T _value; +// public T getValue(){ return _value; } + public T getValue(){ return (T) _value; } + public void setValue(T value){ + if (value != null && !value.equals(_value) || !IsFirst) { + _value=value; + if(ChangeNotify!=null) ChangeNotify.Run(value); + changedNotifys.values().forEach(item->{if(item!=null) item.Run(value);}); + IsFirst = true; + } + } +} + diff --git a/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/ShortLib.java b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/ShortLib.java new file mode 100644 index 00000000..43968463 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/DataUtil/ShortLib.java @@ -0,0 +1,51 @@ +package com.bonait.bnframework.HBL.DataUtil; + + + + +import com.bonait.bnframework.HBL.Enum.DataFormat; + +import java.nio.ByteBuffer; + +public class ShortLib { + public static short ToShort(byte[] bytes, DataFormat df) { + byte[] res= new ByteTransDataFormat().ByteTransDataFormat2(bytes,df,0); + short result= ByteBuffer.wrap(res).getShort(); + return result; + } + + public static short[] ToShorts(byte[] bytes, DataFormat df) { + byte[] tempBytes=new byte[bytes.length]; + if (bytes.length%2!=0){ tempBytes=new byte[bytes.length+1]; } + for (int i=0; i 16 || offset < 1) return false; + return (value & 1 << offset - 1) == 0 ? false : true; + } + + public static short SetBit(short value,int offset, boolean val) + { + if (offset > 16 || offset < 1) return value; + short ConvertValue = (short)(1 << offset - 1); + return (short)(val ? value | ConvertValue : value & ~ConvertValue); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Dialog/AlertDialogButton.java b/app/src/main/java/com/bonait/bnframework/HBL/Dialog/AlertDialogButton.java new file mode 100644 index 00000000..63480341 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Dialog/AlertDialogButton.java @@ -0,0 +1,8 @@ +package com.bonait.bnframework.HBL.Dialog; + +public enum AlertDialogButton { + OK , + OKCancel, + YesNoCancel, + YesNo, +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogActivity.java b/app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogActivity.java new file mode 100644 index 00000000..117c1ffe --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogActivity.java @@ -0,0 +1,15 @@ +package com.bonait.bnframework.HBL.Dialog; + +import android.os.Bundle; + +import androidx.appcompat.app.AppCompatActivity; + +import com.bonait.bnframework.R; + +public class DialogActivity extends AppCompatActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_dialog); + } +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogManager.java b/app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogManager.java new file mode 100644 index 00000000..6963eb55 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogManager.java @@ -0,0 +1,309 @@ +package com.bonait.bnframework.HBL.Dialog; + +import android.app.Activity; +import android.content.Context; +import android.view.View; +import android.widget.Button; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.bonait.bnframework.HBL.Logs.MessageLog; +import com.bonait.bnframework.R; + +/** + * 自定义弹框 + * 需要在 res->values->styles.xml中添加 custom_dialog2样式 + * 需要在layout中添加dialog布局页面 + */ +public class DialogManager { + +// private static DialogView dview; + + private static Context mContext; + + private static Activity mActivity; + + public static void Init(Context context,Activity activity){ + mContext = context; + mActivity=activity; + } + + /** + * 对话框,自定义按钮,非阻塞 + * */ + private static void showDialog(String message, AlertDialogButton btn,DialogType dt, IDialogAction action) { + if(mContext==null) return; + try{ + DialogView dview=new DialogView(mContext, R.layout.activity_dialog, R.style.custom_dialog2); + if (dview != null) { + if (!dview.isShowing()) { + + String btnName1="确定"; + String btnName2="取消"; + if(btn==AlertDialogButton.YesNoCancel||btn==AlertDialogButton.YesNo){ + btnName1="是"; + btnName2="否"; + } + + dview.setCanceledOnTouchOutside(false);//禁用触摸其它区域关闭弹框 + RelativeLayout rlTitle = (RelativeLayout) dview.findViewById(R.id.rl_title); + if(dt== DialogType.提示)rlTitle.setBackgroundResource(R.drawable.dialog_info_title_back); + if(dt== DialogType.警告)rlTitle.setBackgroundResource(R.drawable.dialog_warn_title_back); + if(dt== DialogType.错误)rlTitle.setBackgroundResource(R.drawable.dialog_error_title_back); + TextView Tv=(TextView)dview.findViewById(R.id.tv_Title); + TextView Info=(TextView)dview.findViewById(R.id.tv_Info); + Button ok = (Button)dview.findViewById(R.id.btn_ok); + Button cancel = (Button)dview.findViewById(R.id.btn_cancel); + + Tv.setText(dt.toString()); + Info.setText(message); + ok.setText(btnName1); + cancel.setText(btnName2); + + if(btn==AlertDialogButton.OK)cancel.setVisibility(View.GONE); + + ok.setOnClickListener(view->{ + if(action!=null)action.ExitDialog(true); + hide(dview); + }); + + cancel.setOnClickListener(view->{ + if(action!=null)action.ExitDialog(false); + hide(dview); + }); + dview.show(); + } + } + }catch(Exception e){ + MessageLog.ShowError("打开弹框异常:"+e.toString()); + } + } + + /** + * 对话框,自定义按钮,非阻塞 + * */ + private static void showDialog(Context ct,String message, AlertDialogButton btn,DialogType dt, IDialogAction action) { + if(ct==null) return; + try{ + DialogView dview=new DialogView(ct, R.layout.activity_dialog, R.style.custom_dialog2); + if (dview != null) { + if (!dview.isShowing()) { + + String btnName1="确定"; + String btnName2="取消"; + if(btn==AlertDialogButton.YesNoCancel||btn==AlertDialogButton.YesNo){ + btnName1="是"; + btnName2="否"; + } + + dview.setCanceledOnTouchOutside(false);//禁用触摸其它区域关闭弹框 + RelativeLayout rlTitle = (RelativeLayout) dview.findViewById(R.id.rl_title); + if(dt== DialogType.提示)rlTitle.setBackgroundResource(R.drawable.dialog_info_title_back); + if(dt== DialogType.警告)rlTitle.setBackgroundResource(R.drawable.dialog_warn_title_back); + if(dt== DialogType.错误)rlTitle.setBackgroundResource(R.drawable.dialog_error_title_back); + TextView Tv=(TextView)dview.findViewById(R.id.tv_Title); + TextView Info=(TextView)dview.findViewById(R.id.tv_Info); + Button ok = (Button)dview.findViewById(R.id.btn_ok); + Button cancel = (Button)dview.findViewById(R.id.btn_cancel); + + Tv.setText(dt.toString()); + Info.setText(message); + ok.setText(btnName1); + cancel.setText(btnName2); + + if(btn==AlertDialogButton.OK)cancel.setVisibility(View.GONE); + + ok.setOnClickListener(view->{ + if(action!=null)action.ExitDialog(true); + hide(dview); + }); + + cancel.setOnClickListener(view->{ + if(action!=null)action.ExitDialog(false); + hide(dview); + }); + dview.show(); + } + } + }catch(Exception e){ + MessageLog.ShowError("打开弹框异常:"+e.toString()); + } + } + + /** + * 对话框,自定义按钮,非阻塞 + * */ + private static void showDialog(Activity activity,String message, AlertDialogButton btn,DialogType dt, IDialogAction action) { + if(activity==null) return; + try{ + DialogView dview1=new DialogView(activity, R.layout.activity_dialog, R.style.custom_dialog2); + if (dview1 != null) { + if (!dview1.isShowing()) { + + String btnName1="确定"; + String btnName2="取消"; + if(btn==AlertDialogButton.YesNoCancel||btn==AlertDialogButton.YesNo){ + btnName1="是"; + btnName2="否"; + } + + dview1.setCanceledOnTouchOutside(false);//禁用触摸其它区域关闭弹框 + RelativeLayout rlTitle = (RelativeLayout) dview1.findViewById(R.id.rl_title); + if(dt== DialogType.提示)rlTitle.setBackgroundResource(R.drawable.dialog_info_title_back); + if(dt== DialogType.警告)rlTitle.setBackgroundResource(R.drawable.dialog_warn_title_back); + if(dt== DialogType.错误)rlTitle.setBackgroundResource(R.drawable.dialog_error_title_back); + TextView Tv=(TextView)dview1.findViewById(R.id.tv_Title); + TextView Info=(TextView)dview1.findViewById(R.id.tv_Info); + Button ok = (Button)dview1.findViewById(R.id.btn_ok); + Button cancel = (Button)dview1.findViewById(R.id.btn_cancel); + + Tv.setText(dt.toString()); + Info.setText(message); + ok.setText(btnName1); + cancel.setText(btnName2); + + if(btn==AlertDialogButton.OK)cancel.setVisibility(View.GONE); + + ok.setOnClickListener(view->{ + if(action!=null)action.ExitDialog(true); + hide(dview1); + }); + + cancel.setOnClickListener(view->{ + if(action!=null)action.ExitDialog(false); + hide(dview1); + }); + dview1.show(); + } + } + }catch(Exception e){ + MessageLog.ShowError("打开弹框异常:"+e.toString()); + } + } + + /** + * 隐藏弹框 + * @param view + */ + private static void hide(DialogView view) { + if (view != null) { + if (view.isShowing()) { + view.dismiss(); + } + } + } + + /** + * 信息提示框 + * @param message 提示信息 + * @param btn 显示按钮 + * @param action 执行回调 + */ + public static void showInfo(String message, AlertDialogButton btn, IDialogAction action) { + if(mActivity!=null) + mActivity.runOnUiThread(()->{showDialog(message,btn,DialogType.提示,action);}); + else showDialog(message,btn,DialogType.提示,action); + } + + /** + * 警告提示框 + * @param message 警告信息 + * @param btn 显示按钮 + * @param action 执行回调 + */ + public static void showWarn(String message, AlertDialogButton btn, IDialogAction action) { + if(mActivity!=null) + mActivity.runOnUiThread(()->{showDialog(message,btn,DialogType.警告,action);}); + else showDialog(message,btn,DialogType.警告,action); + } + + /** + * 错误提示框 + * @param message 错误信息 + * @param btn 显示按钮 + * @param action 执行回调 + */ + public static void showError(String message, AlertDialogButton btn, IDialogAction action) { + if(mActivity!=null) + mActivity.runOnUiThread(()->{showDialog(message,btn,DialogType.错误,action);}); + else showDialog(message,btn,DialogType.错误,action); + } + + + + /** + * 信息提示框 + * @param message 提示信息 + * @param btn 显示按钮 + * @param action 执行回调 + */ + public static void showInfo( Context ct,String message, AlertDialogButton btn, IDialogAction action) { + if(mActivity!=null) + mActivity.runOnUiThread(()->{showDialog(ct,message,btn,DialogType.提示,action);}); + else showDialog(ct,message,btn,DialogType.提示,action); + } + + /** + * 警告提示框 + * @param message 警告信息 + * @param btn 显示按钮 + * @param action 执行回调 + */ + public static void showWarn( Context ct,String message, AlertDialogButton btn, IDialogAction action) { + if(mActivity!=null) + mActivity.runOnUiThread(()->{showDialog(ct,message,btn,DialogType.警告,action);}); + else showDialog(ct,message,btn,DialogType.警告,action); + } + + /** + * 错误提示框 + * @param message 错误信息 + * @param btn 显示按钮 + * @param action 执行回调 + */ + public static void showError( Context ct,String message, AlertDialogButton btn, IDialogAction action) { + if(mActivity!=null) + mActivity.runOnUiThread(()->{showDialog(ct,message,btn,DialogType.错误,action);}); + else showDialog(ct,message,btn,DialogType.错误,action); + } + + + + /** + * 信息提示框 + * @param message 提示信息 + * @param btn 显示按钮 + * @param action 执行回调 + */ + public static void showInfo( Activity activity,String message, AlertDialogButton btn, IDialogAction action) { + if(activity!=null) + activity.runOnUiThread(()->{showDialog(activity,message,btn,DialogType.提示,action);}); + else showDialog(activity,message,btn,DialogType.提示,action); + } + + /** + * 警告提示框 + * @param message 警告信息 + * @param btn 显示按钮 + * @param action 执行回调 + */ + public static void showWarn(Activity activity,String message, AlertDialogButton btn, IDialogAction action) { + if(activity!=null) + activity.runOnUiThread(()->{showDialog(activity,message,btn,DialogType.警告,action);}); + else showDialog(activity,message,btn,DialogType.警告,action); + } + + /** + * 错误提示框 + * @param message 错误信息 + * @param btn 显示按钮 + * @param action 执行回调 + */ + public static void showError( Activity activity,String message, AlertDialogButton btn, IDialogAction action) { + if(activity!=null) + activity.runOnUiThread(()->{showDialog(activity,message,btn,DialogType.错误,action);}); + else showDialog(activity,message,btn,DialogType.错误,action); + } + +} + diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogType.java b/app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogType.java new file mode 100644 index 00000000..fc889ef7 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogType.java @@ -0,0 +1,7 @@ +package com.bonait.bnframework.HBL.Dialog; + +public enum DialogType { + 警告, + 提示, + 错误 +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogView.java b/app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogView.java new file mode 100644 index 00000000..57ebb8a2 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Dialog/DialogView.java @@ -0,0 +1,35 @@ +package com.bonait.bnframework.HBL.Dialog; + +import android.app.Activity; +import android.app.Dialog; +import android.content.Context; +import android.view.Window; + +import androidx.annotation.NonNull; + +public class DialogView extends Dialog { + + public DialogView(@NonNull Context context, int layout, int style, int gravity) { + super(context, style); + setContentView(layout); + Window mWindow = getWindow(); +// WindowManager.LayoutParams params = mWindow.getAttributes(); +// params.width = WindowManager.LayoutParams.MATCH_PARENT; +// params.height = WindowManager.LayoutParams.WRAP_CONTENT; +// params.gravity = gravity; +// mWindow.setAttributes(params); + } + + public DialogView(@NonNull Context context, int layout, int style) { + super(context, style); + setContentView(layout); + Window mWindow = getWindow(); + } + + public DialogView(@NonNull Activity activity, int layout, int style) { + super(activity, style); + setContentView(layout); + Window mWindow = getWindow(); + } + +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Dialog/IDialogAction.java b/app/src/main/java/com/bonait/bnframework/HBL/Dialog/IDialogAction.java new file mode 100644 index 00000000..48a6cefc --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Dialog/IDialogAction.java @@ -0,0 +1,6 @@ +package com.bonait.bnframework.HBL.Dialog; + +public interface IDialogAction { + void ExitDialog(boolean status); + +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Enum/DataFormat.java b/app/src/main/java/com/bonait/bnframework/HBL/Enum/DataFormat.java new file mode 100644 index 00000000..af51f337 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Enum/DataFormat.java @@ -0,0 +1,8 @@ +package com.bonait.bnframework.HBL.Enum; + +public enum DataFormat { + ABCD, + CDAB, + BADC, + DCBA +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Executor.java b/app/src/main/java/com/bonait/bnframework/HBL/Executor.java new file mode 100644 index 00000000..6be2fe2a --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Executor.java @@ -0,0 +1,40 @@ +package com.bonait.bnframework.HBL; + + + +import com.bonait.bnframework.HBL.Interface.IRun; +import com.bonait.bnframework.HBL.Logs.MessageLog; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * 异步方法 + */ +public class Executor { + + private static Executor mInstance; //实例变量设置私有,防止直接通过类名访问 + + private Executor() { //默认构造函数私有,防止类外直接new创建对象 + } + + public static synchronized Executor get() { //静态同步方法作为唯一的实例对象获取方式 + if (mInstance == null) { + mInstance = new Executor(); + } + return mInstance; + } + private ExecutorService executor= Executors.newCachedThreadPool() ; + + public void runThread(IRun run) { + executor.submit(()->{ + try { + if(run!=null)run.Run(); + }catch(Exception ex) { + MessageLog.ShowError("runThread 异常:"+ex.getMessage()); + } + }); + } + + +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Interface/IRun.java b/app/src/main/java/com/bonait/bnframework/HBL/Interface/IRun.java new file mode 100644 index 00000000..2f31cac3 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Interface/IRun.java @@ -0,0 +1,5 @@ +package com.bonait.bnframework.HBL.Interface; + +public interface IRun { + void Run(); +} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/I/IRunT.java b/app/src/main/java/com/bonait/bnframework/HBL/Interface/IRunT.java similarity index 51% rename from app/src/main/java/com/bonait/bnframework/common/helper/I/IRunT.java rename to app/src/main/java/com/bonait/bnframework/HBL/Interface/IRunT.java index a1670df8..d9a438ce 100644 --- a/app/src/main/java/com/bonait/bnframework/common/helper/I/IRunT.java +++ b/app/src/main/java/com/bonait/bnframework/HBL/Interface/IRunT.java @@ -1,5 +1,7 @@ -package com.bonait.bnframework.common.helper.I; +package com.bonait.bnframework.HBL.Interface; public interface IRunT { void Run(T t); } + + diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Interface/IRunT2.java b/app/src/main/java/com/bonait/bnframework/HBL/Interface/IRunT2.java new file mode 100644 index 00000000..936688f3 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Interface/IRunT2.java @@ -0,0 +1,5 @@ +package com.bonait.bnframework.HBL.Interface; + +public interface IRunT2 { + void Run(T1 t1, T2 t2);; +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Logs/IMessageLogNotify.java b/app/src/main/java/com/bonait/bnframework/HBL/Logs/IMessageLogNotify.java new file mode 100644 index 00000000..5c23a57b --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Logs/IMessageLogNotify.java @@ -0,0 +1,7 @@ +package com.bonait.bnframework.HBL.Logs; + +public interface IMessageLogNotify { + void ErrorMsg(String msg); + void InfoMsg(String msg); + void WarnMsg(String msg); +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Logs/MessageLog.java b/app/src/main/java/com/bonait/bnframework/HBL/Logs/MessageLog.java new file mode 100644 index 00000000..0bc1b775 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Logs/MessageLog.java @@ -0,0 +1,62 @@ +package com.bonait.bnframework.HBL.Logs; + +import android.util.Log; + +import com.bonait.bnframework.HBL.Thread.ThreadManager; +import com.bonait.bnframework.common.db.QueryDB; +import com.bonait.bnframework.common.db.mode.BPA_ALERTLOG; + +import java.util.concurrent.ConcurrentLinkedQueue; + +public class MessageLog { + private static IMessageLogNotify MsgNotify; + private static ConcurrentLinkedQueue msgQueue=new ConcurrentLinkedQueue(); + private static void Init(){ + MsgNotify = new IMessageLogNotify() { + @Override + public void ErrorMsg(String msg) { + Log.e("错误日志",msg); + } + + @Override + public void InfoMsg(String msg) { + Log.i("信息日志",msg); + } + + @Override + public void WarnMsg(String msg) { + Log.w("警告日志",msg); + } + }; + ThreadManager.get().StartLong("日志信息保存",true,()->{ + while(msgQueue.size()>0){ + String msg= msgQueue.poll(); + BPA_ALERTLOG log= new BPA_ALERTLOG(); + log.text=msg; + QueryDB.AddAlertlog(log); + } + Thread.sleep(2000); + }); + } + + public static void ShowInfo(String msg) { + if (MsgNotify == null)Init(); + MsgNotify.InfoMsg(msg); + } + + public static void ShowWarning(String msg) { + if (MsgNotify == null)Init(); + MsgNotify.WarnMsg(msg); + } + + public static void ShowError(String msg) { + if (MsgNotify == null)Init(); + MsgNotify.ErrorMsg(msg); + } + + public static void ShowError(Exception e) { + if (MsgNotify == null)Init(); + MsgNotify.ErrorMsg(e.toString()); + } + +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/NetworkUtils.java b/app/src/main/java/com/bonait/bnframework/HBL/NetworkUtils.java new file mode 100644 index 00000000..8493a5de --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/NetworkUtils.java @@ -0,0 +1,230 @@ +package com.bonait.bnframework.HBL; + + +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.Network; +import android.net.NetworkCapabilities; +import android.net.NetworkInfo; +import android.net.NetworkRequest; +import android.os.Build; +import android.util.Log; + +import java.io.DataOutputStream; + +/** + * Created by LY on 2019/1/4. + */ +public class NetworkUtils { + //判断网络连接是否可用(返回true表示网络可用,false为不可用) + public static boolean checkNetworkAvailable(Context context) { + //获取手机所有链接管理对象(包括对Wi-Fi,net等连接的管理) + ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + if (manager == null) { + return false; + } else { + //获取NetworkInfo对象 + NetworkInfo[] info = manager.getAllNetworkInfo(); + if (info != null && info.length > 0) { + for (int i = 0; i < info.length; i++) { + System.out.println(i + "状态" + info[i].getState()); + System.out.println(i + "类型" + info[i].getTypeName()); + // 判断当前网络状态是否为连接状态 + if (info[i].getState() == NetworkInfo.State.CONNECTED) { + return true; + } + } + } + } + return false; + } + /** + * 检测当的网络(WLAN、4G/3G/2G)状态,兼容Android 6.0以下 + * @param context Context + * @return true 表示网络可用 + */ + public static boolean isNetworkConnected(Context context) { + boolean result = false; + try { + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (cm != null) { + NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork()); + if (capabilities != null) { + if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { + result = true; + } else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) { + result = true; + } + } + } + } else { + if (cm != null) { + NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + if (activeNetwork != null) { + // connected to the internet + if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) { + result = true; + } else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) { + result = true; + } + } + } + } + + } catch (Exception e) { + return false; + } + + return result; + } + + /** + * 判断是否是移动网络连接 + * */ + public static boolean isActiveNetworkMobile(Context context) { + ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + if (connectivityManager != null) { + NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); + return networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE; + } + return false; + } + + /** + * 判断是否是wifi + * */ + public static boolean isActiveNetworkWifi(Context context) { + ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + if (connectivityManager != null) { + NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); + return networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI; + } + return false; + } + + /** + * @deprecated 请先使用 {@link NetworkUtils#isNetworkConnected(Context)} 方法 + * + * 检测当的网络(WLAN、4G/3G/2G)状态 + * + * @param context Context + * @return true 表示网络可用 + */ + @Deprecated + public static boolean checkNet(Context context) { + + try { + ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + if (connectivity != null) { + + NetworkInfo info = connectivity.getActiveNetworkInfo(); + if (info != null && info.isConnected()) { + + /*if (info.getState() == NetworkInfo.State.CONNECTED) { + return true; + }*/ + NetworkCapabilities networkCapabilities = connectivity.getNetworkCapabilities(connectivity.getActiveNetwork()); + return networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); + } + } + } catch (Exception e) { + return false; + } + return false; + } + + /** + * 绑定有线网络 + * @param context + */ + public static void connetEnternet(Context context) + { + ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkRequest.Builder builder = new NetworkRequest.Builder(); + builder.addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET); + //builder.addTransportType(NetworkCapabilities.TRANSPORT_WIFI); + NetworkRequest networkRequest = builder.build(); + connManager.requestNetwork(networkRequest, new ConnectivityManager.NetworkCallback() { + @Override + public void onAvailable(Network network) { + super.onAvailable(network); + connManager.bindProcessToNetwork(network); // 绑定应用程序到有线网络 + } + }); + } + + /** + * 绑定有线网络 + * @param context + */ + public static void connetWifi(Context context) + { + ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkRequest.Builder builder = new NetworkRequest.Builder(); + builder.addTransportType(NetworkCapabilities.TRANSPORT_WIFI); + NetworkRequest networkRequest = builder.build(); + connManager.requestNetwork(networkRequest, new ConnectivityManager.NetworkCallback() { + @Override + public void onAvailable(Network network) { + super.onAvailable(network); + connManager.bindProcessToNetwork(network); // 绑定应用程序到有线网络 + } + }); + } + + /** + * 同步时间 + */ + public static void SynchronizationTime() + { + new Thread(new Runnable() { + @Override + public void run() { + try { + exec3("settings put global auto_time 0"); + Thread.sleep(500); + exec3("settings put global auto_time 1"); + } catch (InterruptedException e) { + + } + } + }).start(); + } + /** + * 发送 + * @param cmds + */ + public static void exec3(String... cmds) { + StringBuffer command = new StringBuffer(); + if (cmds.length <= 0) { + return; + } + for (String cmd : cmds) { + command.append(cmd).append("\n"); + } + Process process = null; + DataOutputStream os = null; + try { + process = Runtime.getRuntime().exec("su"); + // process = Runtime.getRuntime().exec("system/bin/su"); + os = new DataOutputStream(process.getOutputStream()); + os.write(command.toString().getBytes()); + os.writeBytes("exit\n"); + os.flush(); + process.waitFor(); + } catch (Exception e) { + e.printStackTrace(); + Log.e("eeee",""+e.toString()); + } finally { + try { + os.close(); + } catch (Exception e) { + e.printStackTrace(); + } + if(process!=null){ + process.destroy(); + } + } + } +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/NotifyEvent.java b/app/src/main/java/com/bonait/bnframework/HBL/NotifyEvent.java new file mode 100644 index 00000000..9ea70c08 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/NotifyEvent.java @@ -0,0 +1,60 @@ +package com.bonait.bnframework.HBL; + +import com.bonait.bnframework.HBL.Interface.IRun; +import com.bonait.bnframework.HBL.Interface.IRunT; +import com.bonait.bnframework.HBL.Result.OperateResult; + +import java.util.concurrent.ConcurrentHashMap; + +public class NotifyEvent { + private static volatile NotifyEvent _instance; + public synchronized static NotifyEvent get(){ + if(_instance == null)_instance = new NotifyEvent(); + return _instance; + } + private NotifyEvent(){} + private ConcurrentHashMap _runMap = new ConcurrentHashMap(); + + public void Register(String name,IRun run){ + _runMap.put(name,run); + } + + public void Register(String name, IRunT run){ + _runMap.put(name,run); + } + + public OperateResult Send(String name){ + try{ + if(_runMap.containsKey(name)&&_runMap.get(name)!=null){ + if(_runMap.get(name) instanceof IRun){ + ((IRun)_runMap.get(name)).Run(); + return OperateResult.CreateSuccess(); + }else{ + return OperateResult.CreateFailed("注册类型和发送消息类型不匹配"); + } + }else{ + return OperateResult.CreateFailed(name+"消息未注册"); + } + }catch(Exception e){ + return OperateResult.CreateFailed(e); + } + } + + public OperateResult Send(String name, T value){ + try{ + if(_runMap.containsKey(name)&&_runMap.get(name)!=null){ + if(_runMap.get(name) instanceof IRunT){ + ((IRunT)_runMap.get(name)).Run(value); + return OperateResult.CreateSuccess(); + }else{ + return OperateResult.CreateFailed("注册类型和发送消息类型不匹配"); + } + }else{ + return OperateResult.CreateFailed(name+"消息未注册"); + } + }catch(Exception e){ + return OperateResult.CreateFailed(e); + } + } + +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Result/IResult.java b/app/src/main/java/com/bonait/bnframework/HBL/Result/IResult.java new file mode 100644 index 00000000..13655727 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Result/IResult.java @@ -0,0 +1,30 @@ +package com.bonait.bnframework.HBL.Result; + + +public abstract class IResult { + /** + * 是否成功 + */ + public boolean isSuccess ; + + /** + * 返回消息 + */ + public String message; + + /** + * 操作代码 + */ + public ResultCode resultCode = ResultCode.Default ; + + abstract void setErrorMsg(String msg); + + public boolean getIsSuccess(){ + return resultCode==ResultCode.Success; + } + + public void setIsSuccess(boolean tempSuccess){ + isSuccess= tempSuccess; + resultCode = tempSuccess ? ResultCode.Success : ResultCode.Fail; + } +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Result/OperateResult.java b/app/src/main/java/com/bonait/bnframework/HBL/Result/OperateResult.java new file mode 100644 index 00000000..94300d35 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Result/OperateResult.java @@ -0,0 +1,78 @@ +package com.bonait.bnframework.HBL.Result; + +import com.bonait.bnframework.HBL.Interface.IRun; +import com.bonait.bnframework.HBL.Logs.MessageLog; + +public class OperateResult extends IResult { + + public OperateResult(){ + + } + + public OperateResult(Exception ex){ + message = ex.getMessage()+"\rException:"+ex.toString(); + resultCode = ResultCode.Exception; + isSuccess=false; + } + + public OperateResult(String msg, ResultCode rc) + { + message = msg; + resultCode = rc; + isSuccess=false; + } + + public OperateResult(ResultCode rc) + { + resultCode = rc; + isSuccess=true; + } + + + @Override + public void setErrorMsg(String msg) { + message =message+ msg; + isSuccess=false; + resultCode = ResultCode.Fail; + } + + public OperateResult OnSource(IRun action){ + if(action!=null&&getIsSuccess())action.Run(); + return this; + } + + public OperateResult OnFailed(IRun action){ + try{ + if(action!=null&&!getIsSuccess())action.Run(); + }catch(Exception e){ + MessageLog.ShowError(e); + } + return this; + } + + public OperateResult OnFinally(IRun action){ + try{ + if(action!=null)action.Run(); + }catch(Exception e){ + MessageLog.ShowError(e); + } + return this; + } + + public static OperateResult CreateSuccess() + { + return new OperateResult(ResultCode.Success); + } + + public static OperateResult CreateFailed(String msg) + { + MessageLog.ShowError(msg); + return new OperateResult(msg, ResultCode.Fail); + } + + public static OperateResult CreateFailed(Exception ex) + { + MessageLog.ShowError(ex.toString()); + return new OperateResult(ex); + } +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Result/OperateResultT.java b/app/src/main/java/com/bonait/bnframework/HBL/Result/OperateResultT.java new file mode 100644 index 00000000..8010b7ac --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Result/OperateResultT.java @@ -0,0 +1,88 @@ +package com.bonait.bnframework.HBL.Result; + + +import com.bonait.bnframework.HBL.Interface.IRunT; +import com.bonait.bnframework.HBL.Logs.MessageLog; + +public class OperateResultT extends IResult +{ + public OperateResultT(){} + public OperateResultT(Exception ex) { + message = ex.getMessage()+"\rException:"+ex.toString(); + resultCode = ResultCode.Exception; + isSuccess=false; + } + + public OperateResultT(String msg, ResultCode rc ){ + message = msg; + resultCode = rc; + isSuccess=false; + } + + public OperateResultT(ResultCode rc){ + resultCode = rc; + isSuccess=true; + } + + @Override + public void setErrorMsg(String msg) { + message =message+ msg; + isSuccess=false; + resultCode = ResultCode.Fail; + } + + public OperateResultT(T content, String msg, ResultCode rc){ + Content = content; + message = msg; + resultCode = rc; + isSuccess=getIsSuccess(); + } + + public T Content ; + + public void setContent(T value){ + Content = value; + resultCode = ResultCode.Success; + isSuccess=true; + } + + public OperateResultT OnSource(IRunT> action){ + try{ + if(action!=null&&getIsSuccess())action.Run(this); + }catch(Exception e){ + MessageLog.ShowError(e); + } + return this; + } + + public OperateResultT OnFailed(IRunT> action){ + try{ + if(action!=null&&!getIsSuccess())action.Run(this); + }catch(Exception e){ + MessageLog.ShowError(e); + } + return this; + } + + public OperateResultT OnFinally(IRunT> action){ + if(action!=null)action.Run(this); + return this; + } + + public static OperateResultT CreateSuccess(T value) + { + return new OperateResultT(value,"", ResultCode.Success); + } + + public static OperateResultT CreateFailedT(String msg) + { + MessageLog.ShowError(msg); + return new OperateResultT( msg, ResultCode.Fail); + } + + public static OperateResultT CreateFailedT(Exception ex) + { + MessageLog.ShowError(ex.toString()); + return new OperateResultT(ex); + } +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Result/ResultCode.java b/app/src/main/java/com/bonait/bnframework/HBL/Result/ResultCode.java new file mode 100644 index 00000000..22aefeff --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Result/ResultCode.java @@ -0,0 +1,38 @@ +package com.bonait.bnframework.HBL.Result; + +public enum ResultCode { + /** + * 默认 + */ + Default, + + /** + * 错误 + */ + Error, + + /** + * 异常 + */ + Exception, + + /** + * 成功 + */ + Success, + + /** + * 失败 + */ + Fail, + + /** + * 操作超时 + */ + Overtime, + + /** + * 操作取消 + */ + Canceled +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Thread/IThread.java b/app/src/main/java/com/bonait/bnframework/HBL/Thread/IThread.java new file mode 100644 index 00000000..74129de7 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Thread/IThread.java @@ -0,0 +1,5 @@ +package com.bonait.bnframework.HBL.Thread; + +public interface IThread { + void Run() throws Exception; +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Thread/IThreadComplete.java b/app/src/main/java/com/bonait/bnframework/HBL/Thread/IThreadComplete.java new file mode 100644 index 00000000..0b58eb9b --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Thread/IThreadComplete.java @@ -0,0 +1,7 @@ +package com.bonait.bnframework.HBL.Thread; + +public interface IThreadComplete { + void Run() throws Exception; + + void RunComplete() throws Exception; +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Thread/ThreadManager.java b/app/src/main/java/com/bonait/bnframework/HBL/Thread/ThreadManager.java new file mode 100644 index 00000000..6a7fbb89 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Thread/ThreadManager.java @@ -0,0 +1,105 @@ +package com.bonait.bnframework.HBL.Thread; + +import com.bonait.bnframework.HBL.Logs.MessageLog; + +import java.util.concurrent.ConcurrentHashMap; + +public class ThreadManager { + private static volatile ThreadManager _Instance; + + public static ThreadManager get() { + if (_Instance == null) + _Instance = new ThreadManager(); + return _Instance; + } + + private ThreadManager() { + + } + + public long RestartInterval = 3000; + ConcurrentHashMap tm = new ConcurrentHashMap<>(); + + private void Sleep(long millis) { + try { + Thread.sleep(millis); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + + public void StartLong(String Key, boolean IsRestart, IThreadComplete _thread) { + if (!tm.containsKey(Key)) { + tm.put(Key, new ThreadModel()); + tm.get(Key).RunThread = _thread; + tm.get(Key).ThreadObj = new Thread(() -> { + MessageLog.ShowInfo("启动线程:" + Key); + while (!tm.get(Key).IsCancel) { + if (IsRestart) { + try { + tm.get(Key).RunThread.Run(); + } catch (Exception ex) { + MessageLog.ShowError("多线程:[" + Key + "] 运行发生异常,已重启,错误信息:" + ex.toString()); + Sleep(RestartInterval); + } + } else { + try { + tm.get(Key).RunThread.Run(); + } catch (Exception e) { + MessageLog.ShowError("多线程:[" + Key + "] 运行发生异常,已重启,错误信息:" + e.toString()); + } + } + } + try { + tm.get(Key).RunThread.RunComplete(); + MessageLog.ShowInfo("线程:[" + Key + "]--执行完成"); + } catch (Exception e) { + MessageLog.ShowError("多线程:[" + Key + "] 执行完成任务发生异常,已退出,错误信息:" + e.toString()); + } + tm.remove(Key); + }); + tm.get(Key).ThreadObj.setName(Key); + tm.get(Key).ThreadObj.start(); + } else { + MessageLog.ShowWarning("任务-[" + Key + "]-已存在"); + } + } + + public void StartLong(String Key, boolean IsRestart, IThread _thread) { + if (!tm.containsKey(Key)) { + tm.put(Key, new ThreadModel()); + tm.get(Key).Task = _thread; + tm.get(Key).ThreadObj = new Thread(() -> { + MessageLog.ShowInfo("启动线程:" + Key); + while (!tm.get(Key).IsCancel) { + if (IsRestart) { + try { + tm.get(Key).Task.Run(); + } catch (Exception ex) { + MessageLog.ShowError("多线程:[" + Key + "] 运行发生异常,已重启,错误信息:" + ex.toString()); + Sleep(RestartInterval); + } + } else { + try { + tm.get(Key).Task.Run(); + } catch (Exception e) { + MessageLog.ShowError("多线程:[" + Key + "] 运行发生异常,已重启,错误信息:" + e.toString()); + } + } + } + tm.remove(Key); + }); + tm.get(Key).ThreadObj.setName(Key); + tm.get(Key).ThreadObj.start(); + } else { + MessageLog.ShowWarning("任务-[" + Key + "]-已存在"); + } + } + + public void Stop(String Key) { + if (tm.containsKey(Key)) { + tm.get(Key).IsCancel = true; + } + } + +} diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Thread/ThreadModel.java b/app/src/main/java/com/bonait/bnframework/HBL/Thread/ThreadModel.java new file mode 100644 index 00000000..dc83ef9e --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/HBL/Thread/ThreadModel.java @@ -0,0 +1,8 @@ +package com.bonait.bnframework.HBL.Thread; + +public class ThreadModel { + public IThreadComplete RunThread; + public IThread Task; + public boolean IsCancel; + public Thread ThreadObj; +} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/RTrig.java b/app/src/main/java/com/bonait/bnframework/HBL/Trig/RTrig.java similarity index 89% rename from app/src/main/java/com/bonait/bnframework/common/helper/RTrig.java rename to app/src/main/java/com/bonait/bnframework/HBL/Trig/RTrig.java index 72eb8f85..4cb5caa9 100644 --- a/app/src/main/java/com/bonait/bnframework/common/helper/RTrig.java +++ b/app/src/main/java/com/bonait/bnframework/HBL/Trig/RTrig.java @@ -1,6 +1,8 @@ -package com.bonait.bnframework.common.helper; +package com.bonait.bnframework.HBL.Trig; -import com.bonait.bnframework.common.helper.I.IRun; + + +import com.bonait.bnframework.HBL.Interface.IRun; import java.util.concurrent.ConcurrentHashMap; diff --git a/app/src/main/java/com/bonait/bnframework/MainApplication.java b/app/src/main/java/com/bonait/bnframework/MainApplication.java index 8abbd26a..4a02aff1 100644 --- a/app/src/main/java/com/bonait/bnframework/MainApplication.java +++ b/app/src/main/java/com/bonait/bnframework/MainApplication.java @@ -29,8 +29,6 @@ import com.bonait.bnframework.common.db.mode.BPA_USER; import com.bonait.bnframework.common.db.res.AlertLogEnum; import com.bonait.bnframework.common.db.res.UserLogEnum; import com.bonait.bnframework.common.helper.CrashHandler; -import com.bonait.bnframework.common.helper.I.IMessageLogNotify; -import com.bonait.bnframework.common.helper.MessageLog; import com.bonait.bnframework.common.helper.SdCart; import com.bonait.bnframework.common.utils.NetworkUtils; import com.bonait.bnframework.common.utils.ToastUtils; diff --git a/app/src/main/java/com/bonait/bnframework/modules/welcome/model/AppLoginPo.java b/app/src/main/java/com/bonait/bnframework/Model/AppLoginPo.java similarity index 96% rename from app/src/main/java/com/bonait/bnframework/modules/welcome/model/AppLoginPo.java rename to app/src/main/java/com/bonait/bnframework/Model/AppLoginPo.java index da95bed9..0c7f635b 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/welcome/model/AppLoginPo.java +++ b/app/src/main/java/com/bonait/bnframework/Model/AppLoginPo.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.welcome.model; +package com.bonait.bnframework.Model; import java.util.List; diff --git a/app/src/main/java/com/bonait/bnframework/modules/mine/model/UpdateAppPo.java b/app/src/main/java/com/bonait/bnframework/Model/UpdateAppPo.java similarity index 97% rename from app/src/main/java/com/bonait/bnframework/modules/mine/model/UpdateAppPo.java rename to app/src/main/java/com/bonait/bnframework/Model/UpdateAppPo.java index 0ee1d244..0564094b 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/mine/model/UpdateAppPo.java +++ b/app/src/main/java/com/bonait/bnframework/Model/UpdateAppPo.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.mine.model; +package com.bonait.bnframework.Model; import com.google.gson.annotations.SerializedName; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/UserInfo.java b/app/src/main/java/com/bonait/bnframework/Model/UserInfo.java similarity index 85% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/UserInfo.java rename to app/src/main/java/com/bonait/bnframework/Model/UserInfo.java index 8a256076..0508e5cc 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/UserInfo.java +++ b/app/src/main/java/com/bonait/bnframework/Model/UserInfo.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.from.fragment; +package com.bonait.bnframework.Model; import com.bin.david.form.annotation.SmartColumn; import com.bin.david.form.annotation.SmartTable; diff --git a/app/src/main/java/com/bonait/bnframework/Service/AnalogConvert.java b/app/src/main/java/com/bonait/bnframework/Service/AnalogConvert.java new file mode 100644 index 00000000..f36a7639 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/Service/AnalogConvert.java @@ -0,0 +1,136 @@ +package com.bonait.bnframework.Service; + +import android.content.Context; + +import com.bonait.bnframework.common.constant.ConfigName; +import com.bonait.bnframework.common.helper.ConfigUtil; + +/** + * 模拟量转换 + */ +public class AnalogConvert { + + /** + * 模拟量温度上限 + */ + public static short et_Temperature_Analog_Upper_Limit=0; + + /** + * 模拟量温度下限 + */ + public static short et_Temperature_Analog_Lower_Limit=0; + + /** + * 实际温度上限 + */ + public static short et_Temperature_Upper_Limit=0; + + /** + * 实际温度下限 + */ + public static short et_Temperature_Lower_Limit=0; + + /** + * 模拟量压力上限 + */ + public static short et_Pressure_Analog_Upper_Limit=0; + + /** + * 模拟量压力下限 + */ + public static short et_Pressure_Analog_Lower_Limit=0; + + /** + * 实际压力上限 + */ + public static short et_Pressure_Upper_Limit=0; + + /** + * 实际压力下限 + */ + public static short et_Pressure_Lower_Limit=0; + + public static short Scale(short InputValue, short InputMax, short InputMin, short OutMax, short OutMin){ + try{ + float tempValue = (OutMax - OutMin) * (InputValue - InputMin) / (InputMax - InputMin) + OutMin; + short num =(short)tempValue; +// if (num > OutMax) return OutMax; +// if (num < OutMin) return OutMin; + return num; + }catch(Exception e){ + + } + return 0; + } + + /** + * 获取当前实际压力值 + * @param InputValue 当前实际压力的模拟量值 + * @return 当前实际压力值 + */ + public static short getCurrentPressure(short InputValue){ + return Scale(InputValue,et_Pressure_Analog_Upper_Limit,et_Pressure_Analog_Lower_Limit,et_Pressure_Upper_Limit,et_Pressure_Lower_Limit); + } + + /** + * 获取当前实际压力的模拟量值 + * @param InputValue 当前实际压力值 + * @return 对应的模拟量值 + */ + public static short getCurrentPressureAnalog(short InputValue){ + return Scale(InputValue,et_Pressure_Upper_Limit,et_Pressure_Lower_Limit,et_Pressure_Analog_Upper_Limit,et_Pressure_Analog_Lower_Limit); + } + + + /** + * 获取当前实际温度值 + * @param InputValue 当前实际温度的模拟量值 + * @return 当前实际温度值 + */ + public static short getCurrentTemperature(short InputValue){ + return Scale(InputValue,et_Temperature_Analog_Upper_Limit,et_Temperature_Analog_Lower_Limit,et_Temperature_Upper_Limit,et_Temperature_Lower_Limit); + } + + /** + * 获取当前实际温度的模拟量值 + * @param InputValue 当前实际压力值 + * @return 对应的模拟量值 + */ + public static short getCurrentTemperatureAnalog(short InputValue){ + return Scale(InputValue,et_Temperature_Upper_Limit,et_Temperature_Lower_Limit,et_Temperature_Analog_Upper_Limit,et_Temperature_Analog_Lower_Limit); + } + + public static void SaveConfig(){ + Context dishesCon = ConfigName.getInstance().dishesCon; + ConfigUtil.write(dishesCon, "et_Temperature_Analog_Upper_Limit",et_Temperature_Analog_Upper_Limit ); + ConfigUtil.write(dishesCon, "et_Temperature_Analog_Lower_Limit",et_Temperature_Analog_Lower_Limit); + ConfigUtil.write(dishesCon, "et_Temperature_Upper_Limit",et_Temperature_Upper_Limit ); + ConfigUtil.write(dishesCon, "et_Temperature_Lower_Limit",et_Temperature_Lower_Limit); + ConfigUtil.write(dishesCon, "et_Pressure_Analog_Upper_Limit",et_Pressure_Analog_Upper_Limit ); + ConfigUtil.write(dishesCon, "et_Pressure_Analog_Lower_Limit",et_Pressure_Analog_Lower_Limit ); + ConfigUtil.write(dishesCon, "et_Pressure_Upper_Limit",et_Pressure_Upper_Limit ); + ConfigUtil.write(dishesCon, "et_Pressure_Lower_Limit",et_Pressure_Lower_Limit ); + } + + private static short getConfig(String key){ + try{ + Context dishesCon = ConfigName.getInstance().dishesCon; + return (short)ConfigUtil.read(dishesCon, key,0 ); + }catch(Exception e){ + + } + return 0; + } + + public static void ReadConfig(){ + et_Temperature_Analog_Upper_Limit =getConfig("et_Temperature_Analog_Upper_Limit"); + et_Temperature_Analog_Lower_Limit=getConfig("et_Temperature_Analog_Lower_Limit"); + et_Temperature_Upper_Limit =getConfig("et_Temperature_Upper_Limit"); + et_Temperature_Lower_Limit=getConfig("et_Temperature_Lower_Limit"); + et_Pressure_Analog_Upper_Limit =getConfig("et_Pressure_Analog_Upper_Limit"); + et_Pressure_Analog_Lower_Limit =getConfig("et_Pressure_Analog_Lower_Limit"); + et_Pressure_Upper_Limit =getConfig("et_Pressure_Upper_Limit"); + et_Pressure_Lower_Limit =getConfig("et_Pressure_Lower_Limit"); + } + +} diff --git a/app/src/main/java/com/bonait/bnframework/Service/ControlAdress.java b/app/src/main/java/com/bonait/bnframework/Service/ControlAdress.java new file mode 100644 index 00000000..22eea5cc --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/Service/ControlAdress.java @@ -0,0 +1,13 @@ +package com.bonait.bnframework.Service; + +public enum ControlAdress { + 心跳, + 加热档位, + 启动加热, + 停止加热, + 加热模组状态, + 急停按钮状态, + 升降电机上升, + + +} diff --git a/app/src/main/java/com/bonait/bnframework/Service/Func.java b/app/src/main/java/com/bonait/bnframework/Service/Func.java new file mode 100644 index 00000000..5b33b653 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/Service/Func.java @@ -0,0 +1,24 @@ +package com.bonait.bnframework.Service; + +public enum Func { + /** + * 加热功能 + * par:加热温度,加热档位 + */ + 加热, + /** + * 泄压功能 + * par:泄压压力 + */ + 泄压, + /** + * 保温功能 + * par:保温温度,保温时间 + */ + 保温, + /** + *烹饪功能 + * par:烹饪温度,烹饪时间 + */ + 烹饪, +} diff --git a/app/src/main/java/com/bonait/bnframework/Service/ModbusHelper.java b/app/src/main/java/com/bonait/bnframework/Service/ModbusHelper.java new file mode 100644 index 00000000..5df0b503 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/Service/ModbusHelper.java @@ -0,0 +1,206 @@ +package com.bonait.bnframework.Service; + +import com.bonait.bnframework.HBL.Communication.Modbus.ModbusMaster; +import com.bonait.bnframework.HBL.DataUtil.DataType; +import com.bonait.bnframework.HBL.DataUtil.NotifyPropVar; +import com.bonait.bnframework.HBL.Executor; +import com.bonait.bnframework.HBL.Interface.IRunT; +import com.bonait.bnframework.HBL.Logs.MessageLog; +import com.bonait.bnframework.HBL.Result.OperateResult; +import com.bonait.bnframework.HBL.Result.OperateResultT; +import com.bonait.bnframework.HBL.Thread.ThreadManager; +import com.bonait.bnframework.common.db.mode.BPA_CALIBRATION_PAR; +import com.bonait.bnframework.common.utils.ToastUtils; + +import java.util.concurrent.ConcurrentHashMap; + +public class ModbusHelper extends ModbusMaster { + private static volatile ModbusHelper instance = null; + public synchronized static ModbusHelper get(){ + if(instance==null)instance=new ModbusHelper(); + return instance; + } + private ModbusHelper(){} + +// static ConcurrentHashMap controlAddress=new ConcurrentHashMap(){{ +// put(ControlAdress.锅盖上升,new PLCModel("M20", DataType.BOOLEAN, OperationModel.W) ); +// put(ControlAdress.锅盖下降,new PLCModel("M21",DataType.BOOLEAN,OperationModel.W)); +// put(ControlAdress.锅盖开启,new PLCModel("M22",DataType.BOOLEAN,OperationModel.W)); +// put(ControlAdress.锅盖关闭,new PLCModel("M23",DataType.BOOLEAN,OperationModel.W)); +// put(ControlAdress.锅体正转,new PLCModel("M24",DataType.BOOLEAN,OperationModel.W)); +// put(ControlAdress.锅体反转,new PLCModel("M25",DataType.BOOLEAN,OperationModel.W)); +// put(ControlAdress.泄压阀启停,new PLCModel("M26",DataType.BOOLEAN,OperationModel.W)); +// put(ControlAdress.烹饪完成,new PLCModel("M32",DataType.BOOLEAN,OperationModel.R)); +// put(ControlAdress.一键上升,new PLCModel("M0",DataType.BOOLEAN,OperationModel.W)); +// put(ControlAdress.一键下降,new PLCModel("M1",DataType.BOOLEAN,OperationModel.W)); +// put(ControlAdress.一键回位,new PLCModel("M5",DataType.BOOLEAN,OperationModel.W)); +// put(ControlAdress.停止,new PLCModel("M6",DataType.BOOLEAN,OperationModel.W)); +// put(ControlAdress.配方启动,new PLCModel("M11",DataType.BOOLEAN,OperationModel.W)); +// put(ControlAdress.心跳,new PLCModel("D204",DataType.SHORT,OperationModel.W)); +// put(ControlAdress.当前温度,new PLCModel("D100",DataType.SHORT,OperationModel.R)); +// put(ControlAdress.当前压力,new PLCModel("D101",DataType.SHORT,OperationModel.R)); +// put(ControlAdress.允许开盖压力,new PLCModel("D200",DataType.SHORT,OperationModel.RW)); +// put(ControlAdress.排冷气温度,new PLCModel("D203",DataType.SHORT,OperationModel.RW)); +// put(ControlAdress.温度下限,new PLCModel("D210",DataType.SHORT,OperationModel.RW)); +// put(ControlAdress.温度上限,new PLCModel("D211",DataType.SHORT,OperationModel.RW)); +// put(ControlAdress.压力下限,new PLCModel("D213",DataType.SHORT,OperationModel.RW)); +// put(ControlAdress.压力上限,new PLCModel("D214",DataType.SHORT,OperationModel.RW)); +// put(ControlAdress.加热档位,new PLCModel("D300",DataType.SHORT,OperationModel.W)); +// put(ControlAdress.设定压力,new PLCModel("D301",DataType.SHORT,OperationModel.W)); +// put(ControlAdress.计时温度,new PLCModel("D303",DataType.SHORT,OperationModel.W)); +// put(ControlAdress.烹饪时间,new PLCModel("D304",DataType.SHORT,OperationModel.W)); +// put(ControlAdress.当前时间,new PLCModel("D10",DataType.SHORT,OperationModel.R)); +// }}; + + private ConcurrentHashMap calibrationParMap=new ConcurrentHashMap<>(); + public void Add(BPA_CALIBRATION_PAR item){ + if(item==null)return ; + calibrationParMap.put(item.Name,item); + } + private OperateResultT getCalibrationPar(String name){ + if(calibrationParMap.containsKey(name)){ + return OperateResultT.CreateSuccess(calibrationParMap.get(name)); + }else{ + return OperateResultT.CreateFailedT("不存在的校准参数:"+name); + } + } + + private void Sleep(long millis) { + try { + Thread.sleep(millis); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + + + /** + * 加热控制 + * @param GearPosition 加热档位 + * @param command 启动或停止 + */ + public void Heating(short GearPosition,boolean command){ + //D51:档位设置,M50:启动加热,M51:停止加热 + WriteBool(command?"M51":"M50",false); + WriteShort("D51",command?GearPosition:0); + WriteBool(command?"M50":"M51",true); + } + + /** + * 加水控制 + * @param value + */ + public void AddWater(short value){ + getCalibrationPar("加水阀1").OnSource(item->{ + WriteShort("D1000",value); + WriteBool("M4",true); + }) ; + } + + public void AddLiquid(){ + + } + + + + + + + + +// private PLCModel getPLC(ControlAdress func){ +// if(controlAddress.containsKey(func)){ +// return controlAddress.get(func); +// }else{ +// MessageLog.ShowInfo("不存在控制地址:"+func.toString()); +// return new PLCModel(); +// } +// } + + + private void GetPlcStatus(){ + ThreadManager.get().StartLong("PLC变量状态",true,()->{ + +// WriteShort(getPLC(ControlAdress.心跳).PlcAddress, (short) 0); +// +// controlAddress.forEach((key,value)->{ +// if(value.operationModel== OperationModel.R||value.operationModel==OperationModel.RW){ +// if(value.Value.getValue() instanceof Short){ +// OperateResultT res = ReadShort(value.PlcAddress); +// if(res.isSuccess){ +// value.Value .setValue(res.Content); +// } +// }else if (value.Value.getValue() instanceof Boolean){ +// OperateResultT res = ReadBool(value.PlcAddress); +// if(res.isSuccess){ +// value.Value .setValue(res.Content); +// } +// } +// +// } +// }); + Thread.sleep(1); + }); + } + + public NotifyPropVar IsRunning=new NotifyPropVar(false); + + public int CurrentTime=0; + + public void RtuInit(String comName,int baudRate){ + new Thread(()->{ RtuConnect(comName,baudRate).OnSource(()->{ GetPlcStatus();});}).start(); + } + + + /** + * 设置变量监听通知 + * @param func + * @param action + * @param + */ + public void setPLCNotify(ControlAdress func,String key, IRunT action){ +// if(controlAddress.containsKey(func)){ +// controlAddress.get(func).Value.Register(key,action); +// } + } + + /** + * 写布尔信号 + * @param func + * @param value + */ + public void WriteBoolSingle(ControlAdress func, boolean value){ +// if(controlAddress.containsKey(func)){ +// Executor.get().runThread(()->{ +// WriteBool(controlAddress.get(func).PlcAddress,value).OnSource(()->{ +// MessageLog.ShowInfo("写入 "+controlAddress.get(func).PlcAddress+":"+value); +// }); +// }); +// } + } + + /** + * 写脉冲信号 + * @param func + */ + public void PulseSignal(ControlAdress func){ +// if(controlAddress.containsKey(func)){ +// Executor.get().runThread(()->{ +// WriteBool(controlAddress.get(func).PlcAddress,true); +// Sleep(1000); +// WriteBool(controlAddress.get(func).PlcAddress,false); +// }); +// } + } + + public void WriteAsync(String address,T value) { + Executor.get().runThread(()->{ + Write(address,value); + }); + } + +} + + + + diff --git a/app/src/main/java/com/bonait/bnframework/Service/OperationModel.java b/app/src/main/java/com/bonait/bnframework/Service/OperationModel.java new file mode 100644 index 00000000..0e99ee4f --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/Service/OperationModel.java @@ -0,0 +1,16 @@ +package com.bonait.bnframework.Service; + +public enum OperationModel { + /** + * 只读 + */ + R, + /** + * 只写 + */ + W, + /** + * 可读可写 + */ + RW +} diff --git a/app/src/main/java/com/bonait/bnframework/Service/PLCModel.java b/app/src/main/java/com/bonait/bnframework/Service/PLCModel.java new file mode 100644 index 00000000..c236176c --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/Service/PLCModel.java @@ -0,0 +1,23 @@ +package com.bonait.bnframework.Service; + +import com.bonait.bnframework.HBL.DataUtil.NotifyPropVar; + +import java.io.Serializable; + +public class PLCModel { + public String PlcAddress; + public NotifyPropVar Value; + public T getValue(){ + return (T)Value.getValue(); + } + public OperationModel operationModel; + public PLCModel(String add,T defaultValue,OperationModel om){ + PlcAddress = add; + Value = new NotifyPropVar<>(defaultValue); + operationModel = om; + } + + public PLCModel(){ + + } +} diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigation2Activity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/BottomNavigation2Activity.java similarity index 76% rename from app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigation2Activity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/BottomNavigation2Activity.java index 47fe28e8..bc248fdf 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigation2Activity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/BottomNavigation2Activity.java @@ -1,16 +1,14 @@ -package com.bonait.bnframework.modules.home.activity; +package com.bonait.bnframework.ViewModel.ActivityViewModel; import android.os.Bundle; import androidx.annotation.NonNull; +import com.bonait.bnframework.HBL.Logs.MessageLog; +import com.bonait.bnframework.HBL.Thread.IThread; +import com.bonait.bnframework.HBL.Thread.ThreadManager; import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.common.constant.ConfigName; -import com.bonait.bnframework.common.constant.DataBus; -import com.bonait.bnframework.common.helper.I.IThread; -import com.bonait.bnframework.common.helper.MessageLog; -import com.bonait.bnframework.common.helper.ThreadManager; -import com.bonait.bnframework.common.modbus.ModbusTcpServer; import com.bonait.bnframework.common.utils.NetworkUtils; import com.google.android.material.bottomnavigation.BottomNavigationView; @@ -27,10 +25,10 @@ import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.manager.ActivityLifecycleManager; import com.bonait.bnframework.common.base.BaseActivity; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.fragment.Home1Fragment; -import com.bonait.bnframework.modules.home.fragment.Home2Fragment; -import com.bonait.bnframework.modules.home.adapter.FragmentAdapter; -import com.bonait.bnframework.modules.mine.fragment.MyFragment; +import com.bonait.bnframework.ViewModel.FragmentViewModel.Home1Fragment; +import com.bonait.bnframework.ViewModel.FragmentViewModel.Home2Fragment; +import com.bonait.bnframework.ViewModel.Adapter.FragmentAdapter; +import com.bonait.bnframework.ViewModel.FragmentViewModel.MyFragment; import com.lzy.okgo.OkGo; import com.qmuiteam.qmui.widget.QMUIViewPager; @@ -182,37 +180,35 @@ public class BottomNavigation2Activity extends BaseActivity { public void ReconnectModbus() { try { - ThreadManager.Get().StartLong("PLC断线重连线程", true, new IThread() { + ThreadManager.get().StartLong("PLC断线重连线程", true, new IThread() { @Override public void Run() throws InterruptedException { try { - if (ConfigName.getInstance().PlcIsConnect) { - //ping 不通 - boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); - if (!status) //ping 不通 连接 - { - MessageLog.ShowInfo("PLC状态断开,尝试连接..."); - ConfigName.getInstance().PlcIsConnect = false; - } - } else { - boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); - if (status) { - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " PLC通讯正常,准备连接!"); - ModbusTcpServer.ConnectPLC(); - } else { - MessageLog.ShowInfo("PLC状态断开,尝试连接..."); - ConfigName.getInstance().PlcIsConnect = false; - } - } +// if (ConfigName.getInstance().PlcIsConnect) { +// //ping 不通 +// boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); +// if (!status) //ping 不通 连接 +// { +// MessageLog.ShowInfo("PLC状态断开,尝试连接..."); +// ConfigName.getInstance().PlcIsConnect = false; +// } +// } else { +// boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); +// if (status) { +// MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " PLC通讯正常,准备连接!"); +// ModbusTcpServer.ConnectPLC(); +// } else { +// MessageLog.ShowInfo("PLC状态断开,尝试连接..."); +// ConfigName.getInstance().PlcIsConnect = false; +// } +// } Thread.sleep(10000); } catch (Exception e) { Log.i("PLC", "PLC重连接失败!" + e.getMessage()); } } - @Override - public void RunComplete() throws InterruptedException { - } + }); } catch (Exception e) { MessageLog.ShowInfo("重新连接Modbus异常," + e.getMessage()); diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationNewActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/BottomNavigationNewActivity.java similarity index 89% rename from app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationNewActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/BottomNavigationNewActivity.java index 0f7a8ed2..23e66ed3 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationNewActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/BottomNavigationNewActivity.java @@ -1,17 +1,18 @@ -package com.bonait.bnframework.modules.home.activity; +package com.bonait.bnframework.ViewModel.ActivityViewModel; -import androidx.appcompat.app.AppCompatActivity; import androidx.viewpager.widget.ViewPager; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; -import android.view.MenuItem; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; +import com.bonait.bnframework.HBL.Logs.MessageLog; +import com.bonait.bnframework.HBL.Thread.IThread; +import com.bonait.bnframework.HBL.Thread.ThreadManager; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.business.ExecuteTheRecipe; @@ -22,26 +23,17 @@ import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.helper.CountDownTimerExt; -import com.bonait.bnframework.common.helper.I.IThread; import com.bonait.bnframework.common.helper.I.MyClickListener; -import com.bonait.bnframework.common.helper.MessageLog; -import com.bonait.bnframework.common.helper.ThreadManager; import com.bonait.bnframework.common.message.MessageLooper; import com.bonait.bnframework.common.message.MessageManager; -import com.bonait.bnframework.common.modbus.ModbusTcpServer; import com.bonait.bnframework.common.utils.NetworkUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.common.view.BottomNavigationBar; import com.bonait.bnframework.manager.ActivityLifecycleManager; -import com.bonait.bnframework.modules.home.adapter.FragmentAdapter; -import com.bonait.bnframework.modules.home.fragment.Home1Fragment; -import com.bonait.bnframework.modules.home.fragment.Home2Fragment; -import com.bonait.bnframework.modules.home.fragment.Home4Fragment; -import com.bonait.bnframework.modules.home.fragment.HomeFragmentPR; -import com.bonait.bnframework.modules.home.fragment.HomeFragmentSBKZ; -import com.bonait.bnframework.modules.home.fragment.from.CookingActivity; -import com.bonait.bnframework.modules.mine.fragment.MyFragment; -import com.google.android.material.bottomnavigation.BottomNavigationView; +import com.bonait.bnframework.ViewModel.Adapter.FragmentAdapter; +import com.bonait.bnframework.ViewModel.FragmentViewModel.Home4Fragment; +import com.bonait.bnframework.ViewModel.FragmentViewModel.HomeFragmentPR; +import com.bonait.bnframework.ViewModel.FragmentViewModel.HomeFragmentSBKZ; import com.lzy.okgo.OkGo; import com.qmuiteam.qmui.widget.QMUIViewPager; @@ -247,37 +239,35 @@ public class BottomNavigationNewActivity extends BaseActivity { public void ReconnectModbus() { try { - ThreadManager.Get().StartLong("PLC断线重连线程", true, new IThread() { + ThreadManager.get().StartLong("PLC断线重连线程", true, new IThread() { @Override public void Run() throws InterruptedException { - try { - if (ConfigName.getInstance().PlcIsConnect) { - //ping 不通 - boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); - if (!status) //ping 不通 连接 - { - MessageLog.ShowInfo("PLC状态断开,尝试连接..."); - ConfigName.getInstance().PlcIsConnect = false; - } - } else { - boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); - if (status) { - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " PLC通讯正常,准备连接!"); - ModbusTcpServer.ConnectPLC(); - } else { - MessageLog.ShowInfo("PLC状态断开,尝试连接..."); - ConfigName.getInstance().PlcIsConnect = false; - } - } - Thread.sleep(10000); - } catch (Exception e) { - Log.i("PLC", "PLC重连接失败!" + e.getMessage()); - } +// try { +// if (ConfigName.getInstance().PlcIsConnect) { +// //ping 不通 +// boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); +// if (!status) //ping 不通 连接 +// { +// MessageLog.ShowInfo("PLC状态断开,尝试连接..."); +// ConfigName.getInstance().PlcIsConnect = false; +// } +// } else { +// boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); +// if (status) { +// MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " PLC通讯正常,准备连接!"); +// ModbusTcpServer.ConnectPLC(); +// } else { +// MessageLog.ShowInfo("PLC状态断开,尝试连接..."); +// ConfigName.getInstance().PlcIsConnect = false; +// } +// } +// Thread.sleep(10000); +// } catch (Exception e) { +// Log.i("PLC", "PLC重连接失败!" + e.getMessage()); +// } } - @Override - public void RunComplete() throws InterruptedException { - } + }); } catch (Exception e) { MessageLog.ShowInfo("重新连接Modbus异常," + e.getMessage()); diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/BunkerSetupActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/BunkerSetupActivity.java similarity index 90% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/BunkerSetupActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/BunkerSetupActivity.java index 6ad9c6b5..298391ad 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/BunkerSetupActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/BunkerSetupActivity.java @@ -1,6 +1,5 @@ -package com.bonait.bnframework.modules.home.fragment.from; +package com.bonait.bnframework.ViewModel.ActivityViewModel; -import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; import android.app.Activity; @@ -13,19 +12,14 @@ import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.base.BaseActivity; import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.db.QueryDB; -import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; -import com.bonait.bnframework.common.db.mode.BPA_SILOS; import com.bonait.bnframework.common.db.res.lcMode; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.fragment.mode.add_silos_message; -import com.bonait.bnframework.modules.home.fragment.mode.imagebuttom; -import com.bonait.bnframework.modules.home.fragment.mode.jingdutiao1; +import com.bonait.bnframework.ViewModel.CustomView.add_silos_message; +import com.bonait.bnframework.ViewModel.CustomView.imagebuttom; +import com.bonait.bnframework.ViewModel.CustomView.jingdutiao1; import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import java.util.ArrayList; -import java.util.List; - import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CookingActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/CookingActivity.java similarity index 92% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CookingActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/CookingActivity.java index b1c4f2a9..300def2b 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CookingActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/CookingActivity.java @@ -1,51 +1,33 @@ -package com.bonait.bnframework.modules.home.fragment.from; - -import static com.bonait.bnframework.MainApplication.getContext; +package com.bonait.bnframework.ViewModel.ActivityViewModel; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import android.app.Activity; import android.content.Context; -import android.content.Intent; -import android.graphics.Color; -import android.graphics.Typeface; -import android.os.Bundle; -import android.os.CountDownTimer; -import android.os.SystemClock; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; -import android.widget.Chronometer; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import com.bonait.bnframework.HBL.Interface.IRunT; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; -import com.bonait.bnframework.common.base.BaseActivity; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.constant.MessageName; -import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODS; -import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; -import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; -import com.bonait.bnframework.common.db.mode.BPA_SILOS; -import com.bonait.bnframework.common.db.res.lcMode; -import com.bonait.bnframework.common.helper.CountDownTimerExt; -import com.bonait.bnframework.common.helper.I.IRunT; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.fragment.mode.imagebuttom; -import com.bonait.bnframework.modules.home.fragment.mode.imagebuttom3; -import com.bonait.bnframework.modules.home.fragment.mode.jingdutiao; -import com.bonait.bnframework.modules.home.fragment.mode.newhuoli_control; +import com.bonait.bnframework.ViewModel.CustomView.imagebuttom; +import com.bonait.bnframework.ViewModel.CustomView.imagebuttom3; +import com.bonait.bnframework.ViewModel.CustomView.jingdutiao; +import com.bonait.bnframework.ViewModel.CustomView.newhuoli_control; import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.ConcurrentHashMap; import butterknife.BindView; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CookingSimulatedActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/CookingSimulatedActivity.java similarity index 96% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CookingSimulatedActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/CookingSimulatedActivity.java index 36fb895a..980ff797 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CookingSimulatedActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/CookingSimulatedActivity.java @@ -1,17 +1,11 @@ -package com.bonait.bnframework.modules.home.fragment.from; +package com.bonait.bnframework.ViewModel.ActivityViewModel; import static com.bonait.bnframework.MainApplication.getContext; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; -import android.app.Activity; -import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.util.AttributeSet; -import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; @@ -23,22 +17,15 @@ import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.base.BaseActivity; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.DataBus; -import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.db.mode.BPA_SILOS; import com.bonait.bnframework.common.helper.CountDownTimerExt; -import com.bonait.bnframework.common.helper.I.IRunT; -import com.bonait.bnframework.common.helper.I.IWriteCallBack; -import com.bonait.bnframework.common.helper.I.MyClickListener; -import com.bonait.bnframework.common.image.MyBitmapUtils; -import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.fragment.mode.imagebuttom; -import com.bonait.bnframework.modules.home.fragment.mode.imagebuttom3; -import com.bonait.bnframework.modules.home.fragment.mode.jingdutiao; -import com.bonait.bnframework.modules.home.fragment.mode.newhuoli_control; +import com.bonait.bnframework.ViewModel.CustomView.imagebuttom3; +import com.bonait.bnframework.ViewModel.CustomView.jingdutiao; +import com.bonait.bnframework.ViewModel.CustomView.newhuoli_control; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import java.util.ArrayList; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CpActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/CpActivity.java similarity index 95% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CpActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/CpActivity.java index 07cebd7d..a0f1a57f 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CpActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/CpActivity.java @@ -1,9 +1,7 @@ -package com.bonait.bnframework.modules.home.fragment.from; +package com.bonait.bnframework.ViewModel.ActivityViewModel; import static com.bonait.bnframework.MainApplication.getContext; -import androidx.appcompat.app.AppCompatActivity; - import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; @@ -24,18 +22,14 @@ import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; -import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; import com.bonait.bnframework.common.message.MessageLooper; import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.model.mode.CloudGood; import com.bonait.bnframework.common.utils.AlertDialogUtils; -import com.bonait.bnframework.common.utils.ScreenUtils; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.fragment.mode.QDListSectionAdapter; -import com.bonait.bnframework.modules.home.fragment.mode.SectionHeader; -import com.bonait.bnframework.modules.home.fragment.mode.SectionItem; -import com.bonait.bnframework.modules.home.fragment.mode.fragment_plc; -import com.qmuiteam.qmui.widget.QMUITopBar; +import com.bonait.bnframework.ViewModel.CustomView.QDListSectionAdapter; +import com.bonait.bnframework.ViewModel.CustomView.SectionHeader; +import com.bonait.bnframework.ViewModel.CustomView.SectionItem; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CpxzActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/CpxzActivity.java similarity index 94% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CpxzActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/CpxzActivity.java index 96e17787..3bc52448 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CpxzActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/CpxzActivity.java @@ -1,6 +1,5 @@ -package com.bonait.bnframework.modules.home.fragment.from; +package com.bonait.bnframework.ViewModel.ActivityViewModel; -import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import androidx.recyclerview.widget.RecyclerView; import androidx.appcompat.widget.SearchView; @@ -13,8 +12,7 @@ import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.common.view.MyLayoutManager; -import com.bonait.bnframework.modules.home.adapter.sp_adapter; -import com.qmuiteam.qmui.widget.QMUITopBar; +import com.bonait.bnframework.ViewModel.Adapter.sp_adapter; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import butterknife.BindView; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DishTestActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/DishTestActivity.java similarity index 97% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DishTestActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/DishTestActivity.java index 21aac47d..196e3143 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DishTestActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/DishTestActivity.java @@ -1,23 +1,16 @@ -package com.bonait.bnframework.modules.home.fragment.from; +package com.bonait.bnframework.ViewModel.ActivityViewModel; import static com.bonait.bnframework.MainApplication.getContext; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; import android.app.Activity; import android.content.Context; import android.content.Intent; -import android.graphics.Color; -import android.graphics.Typeface; import android.os.Bundle; import android.os.SystemClock; import android.text.InputType; -import android.util.AttributeSet; -import android.view.LayoutInflater; import android.view.View; -import android.widget.AdapterView; import android.widget.Chronometer; import android.widget.EditText; import android.widget.ImageView; @@ -35,28 +28,22 @@ import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; -import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.message.MessageManager; -import com.bonait.bnframework.common.model.mode.MouthFacingEnum; import com.bonait.bnframework.common.model.mode.SpeedEnum; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.adapter.gongxubuzhou_adapter; -import com.bonait.bnframework.modules.home.adapter.gongxubuzhou_adapter1; -import com.bonait.bnframework.modules.home.adapter.gongxubuzhou_adapter2; -import com.bonait.bnframework.modules.home.fragment.mode.fragment_gx; -import com.bonait.bnframework.modules.home.fragment.mode.imagebuttom; -import com.bonait.bnframework.modules.home.fragment.mode.imagebuttom3; -import com.bonait.bnframework.modules.home.fragment.mode.jingdutiao; -import com.bonait.bnframework.modules.home.fragment.mode.newhuoli_control; +import com.bonait.bnframework.ViewModel.Adapter.gongxubuzhou_adapter1; +import com.bonait.bnframework.ViewModel.Adapter.gongxubuzhou_adapter2; +import com.bonait.bnframework.ViewModel.CustomView.imagebuttom; +import com.bonait.bnframework.ViewModel.CustomView.imagebuttom3; +import com.bonait.bnframework.ViewModel.CustomView.newhuoli_control; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; import java.util.ArrayList; import java.util.Collections; -import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/DiyActivity.java similarity index 95% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/DiyActivity.java index aa5ec83d..6baf2926 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/DiyActivity.java @@ -1,22 +1,15 @@ -package com.bonait.bnframework.modules.home.fragment.from; +package com.bonait.bnframework.ViewModel.ActivityViewModel; import static com.bonait.bnframework.MainApplication.getContext; -import androidx.appcompat.app.AppCompatActivity; - -import android.annotation.SuppressLint; import android.content.Intent; -import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.util.AttributeSet; -import android.util.Xml; import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ImageView; @@ -34,30 +27,20 @@ import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.mode.BPA_PROCESS; import com.bonait.bnframework.common.db.mode.BPA_PROCESSModel; -import com.bonait.bnframework.common.helper.I.MyClickListener; -import com.bonait.bnframework.common.helper.MyImage; import com.bonait.bnframework.common.image.MyBitmapUtils; import com.bonait.bnframework.common.message.MessageLooper; import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.adapter.gongxubuzhou_adapter; -import com.bonait.bnframework.modules.home.adapter.lcsz_adapter; -import com.bonait.bnframework.modules.home.fragment.mode.fragment_gx; -import com.bonait.bnframework.modules.home.fragment.mode.item_gx; -import com.qmuiteam.qmui.widget.QMUITopBar; +import com.bonait.bnframework.ViewModel.Adapter.gongxubuzhou_adapter; +import com.bonait.bnframework.ViewModel.CustomView.fragment_gx; +import com.bonait.bnframework.ViewModel.CustomView.item_gx; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.youth.banner.Banner; - -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; -import java.util.IdentityHashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyMemoryActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/DiyMemoryActivity.java similarity index 94% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyMemoryActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/DiyMemoryActivity.java index 73baa4f9..bdcf6473 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyMemoryActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/DiyMemoryActivity.java @@ -1,21 +1,17 @@ -package com.bonait.bnframework.modules.home.fragment.from; - -import static com.bonait.bnframework.MainApplication.getContext; +package com.bonait.bnframework.ViewModel.ActivityViewModel; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; import android.content.Context; -import android.content.Intent; import android.graphics.Color; import android.os.Bundle; -import android.os.CountDownTimer; import android.os.SystemClock; import android.view.View; import android.widget.Chronometer; import android.widget.ImageView; import android.widget.LinearLayout; +import com.bonait.bnframework.HBL.Interface.IRun; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.base.BaseActivity; @@ -23,23 +19,19 @@ import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.db.QueryDB; -import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; -import com.bonait.bnframework.common.db.mode.BPA_PROCESSModel; -import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.fragment.mode.fragment_gx; -import com.bonait.bnframework.modules.home.fragment.mode.huoli_control; -import com.bonait.bnframework.modules.home.fragment.mode.item_gx; +import com.bonait.bnframework.ViewModel.CustomView.fragment_gx; +import com.bonait.bnframework.ViewModel.CustomView.huoli_control; +import com.bonait.bnframework.ViewModel.CustomView.item_gx; import com.litao.slider.NiftySlider; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.textview.QMUILinkTextView; import java.util.ArrayList; @@ -229,17 +221,11 @@ public class DiyMemoryActivity extends BaseActivity { String sdstr= Get速度(sd); BPA_GOODSRECIPE data=Get搅拌(sdstr); DataBus.getInstance().bpa_goodsrecipes.add(data); - ExecuteTheRecipe.WritePLC("搅拌速度", sd, new IWriteCallBack() { - @Override - public void onSuccess() { - if (sd == 0) { - ExecuteTheRecipe.WritePLC("搅拌", false, null); - } else { - ExecuteTheRecipe.WritePLC("搅拌", true, null); - } - } - @Override - public void onFailure(String ErrorMsg) { + ExecuteTheRecipe.WritePLC("搅拌速度", sd, ()->{ + if (sd == 0) { + ExecuteTheRecipe.WritePLC("搅拌", false, null); + } else { + ExecuteTheRecipe.WritePLC("搅拌", true, null); } }); ClikTime=time; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyUpdate1Activity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/DiyUpdate1Activity.java similarity index 98% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyUpdate1Activity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/DiyUpdate1Activity.java index 892fb99f..9bb555b0 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyUpdate1Activity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/DiyUpdate1Activity.java @@ -1,12 +1,10 @@ -package com.bonait.bnframework.modules.home.fragment.from; +package com.bonait.bnframework.ViewModel.ActivityViewModel; import static com.bonait.bnframework.MainApplication.getContext; -import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; import android.content.Intent; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; @@ -15,7 +13,6 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.EditText; -import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.Spinner; @@ -36,10 +33,9 @@ import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.common.view.CircleImageView; -import com.bonait.bnframework.modules.home.adapter.gongxubuzhou_adapter; -import com.bonait.bnframework.modules.home.fragment.mode.fragment_gx; -import com.bonait.bnframework.modules.home.fragment.mode.item_gx; -import com.qmuiteam.qmui.widget.QMUIRadiusImageView2; +import com.bonait.bnframework.ViewModel.Adapter.gongxubuzhou_adapter; +import com.bonait.bnframework.ViewModel.CustomView.fragment_gx; +import com.bonait.bnframework.ViewModel.CustomView.item_gx; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyUpdateActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/DiyUpdateActivity.java similarity index 97% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyUpdateActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/DiyUpdateActivity.java index 142c0f7c..a32eb28f 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyUpdateActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/DiyUpdateActivity.java @@ -1,9 +1,7 @@ -package com.bonait.bnframework.modules.home.fragment.from; +package com.bonait.bnframework.ViewModel.ActivityViewModel; import static com.bonait.bnframework.MainApplication.getContext; -import androidx.appcompat.app.AppCompatActivity; - import android.content.Intent; import android.graphics.drawable.Drawable; import android.os.Bundle; @@ -29,23 +27,18 @@ import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.mode.BPA_PROCESS; import com.bonait.bnframework.common.db.mode.BPA_PROCESSModel; -import com.bonait.bnframework.common.helper.I.MyClickListener; -import com.bonait.bnframework.common.helper.MyImage; import com.bonait.bnframework.common.image.MyBitmapUtils; import com.bonait.bnframework.common.message.MessageLooper; import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.adapter.gongxubuzhou_adapter; -import com.bonait.bnframework.modules.home.fragment.mode.fragment_gx; -import com.bonait.bnframework.modules.home.fragment.mode.item_gx; -import com.qmuiteam.qmui.widget.QMUITopBar; +import com.bonait.bnframework.ViewModel.Adapter.gongxubuzhou_adapter; +import com.bonait.bnframework.ViewModel.CustomView.fragment_gx; +import com.bonait.bnframework.ViewModel.CustomView.item_gx; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.youth.banner.Banner; -import java.net.IDN; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/FileActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/FileActivity.java similarity index 98% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/FileActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/FileActivity.java index 7fa9982f..82dcf97f 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/FileActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/FileActivity.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.from; +package com.bonait.bnframework.ViewModel.ActivityViewModel; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/ImageChooseActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/ImageChooseActivity.java similarity index 84% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/ImageChooseActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/ImageChooseActivity.java index be7b9ad7..959d0098 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/ImageChooseActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/ImageChooseActivity.java @@ -1,7 +1,5 @@ -package com.bonait.bnframework.modules.home.fragment.from; +package com.bonait.bnframework.ViewModel.ActivityViewModel; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.SearchView; import androidx.recyclerview.widget.RecyclerView; import android.os.Bundle; @@ -10,18 +8,13 @@ import android.view.View; import com.bonait.bnframework.R; import com.bonait.bnframework.common.base.BaseActivity; -import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.constant.MessageName; -import com.bonait.bnframework.common.db.mode.BPA_GOODS; -import com.bonait.bnframework.common.helper.AES; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.common.view.MyLayoutManager; -import com.bonait.bnframework.modules.home.adapter.image_sp_adapter; -import com.bonait.bnframework.modules.home.adapter.sp_adapter; -import com.bonait.bnframework.modules.home.fragment.mode.image_sp; -import com.qmuiteam.qmui.widget.QMUITopBar; +import com.bonait.bnframework.ViewModel.Adapter.image_sp_adapter; +import com.bonait.bnframework.ViewModel.CustomView.image_sp; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import java.io.File; diff --git a/app/src/main/java/com/bonait/bnframework/modules/welcome/activity/LoginActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/LoginActivity.java similarity index 97% rename from app/src/main/java/com/bonait/bnframework/modules/welcome/activity/LoginActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/LoginActivity.java index a59a9599..aedbdaa7 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/welcome/activity/LoginActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/LoginActivity.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.welcome.activity; +package com.bonait.bnframework.ViewModel.ActivityViewModel; import android.animation.ObjectAnimator; import android.annotation.SuppressLint; @@ -20,29 +20,23 @@ import android.widget.CompoundButton; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.RelativeLayout; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.common.base.BaseActivity; -import com.bonait.bnframework.common.bg.SnowView; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.Constants; import com.bonait.bnframework.common.constant.SPConstants; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_USER; -import com.bonait.bnframework.common.helper.ActiveMax; import com.bonait.bnframework.common.utils.AlertDialogUtils; -import com.bonait.bnframework.common.utils.AnimationToolUtils; import com.bonait.bnframework.common.utils.AppUtils; import com.bonait.bnframework.common.utils.Des3Utils; import com.bonait.bnframework.common.utils.KeyboardToolUtils; import com.bonait.bnframework.common.utils.PreferenceUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.manager.ActivityLifecycleManager; -import com.bonait.bnframework.modules.home.activity.BottomNavigation2Activity; -import com.bonait.bnframework.modules.home.activity.BottomNavigationNewActivity; -import com.bonait.bnframework.modules.welcome.model.AppLoginPo; +import com.bonait.bnframework.Model.AppLoginPo; import com.bonait.bnframework.test.TestActivity; import com.lzy.okgo.OkGo; import com.lzy.okgo.model.HttpParams; diff --git a/app/src/main/java/com/bonait/bnframework/modules/mine/fragment/from/NoticeActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/NoticeActivity.java similarity index 97% rename from app/src/main/java/com/bonait/bnframework/modules/mine/fragment/from/NoticeActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/NoticeActivity.java index 5f820469..d77dc0b7 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/mine/fragment/from/NoticeActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/NoticeActivity.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.mine.fragment.from; +package com.bonait.bnframework.ViewModel.ActivityViewModel; import androidx.core.content.ContextCompat; import androidx.appcompat.app.AppCompatActivity; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SzActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/SzActivity.java similarity index 89% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SzActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/SzActivity.java index 74ade832..e4f850b1 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SzActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/SzActivity.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.from; +package com.bonait.bnframework.ViewModel.ActivityViewModel; import androidx.annotation.NonNull; @@ -6,7 +6,7 @@ import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.utils.ToastUtils; import com.google.android.material.bottomnavigation.BottomNavigationView; import androidx.viewpager.widget.ViewPager; -import androidx.appcompat.app.AppCompatActivity; + import android.os.Bundle; import android.view.MenuItem; import android.view.View; @@ -16,12 +16,11 @@ import android.widget.RelativeLayout; import com.bonait.bnframework.R; import com.bonait.bnframework.common.base.BaseActivity; -import com.bonait.bnframework.modules.home.adapter.FragmentAdapter; -import com.bonait.bnframework.modules.home.fragment.from.fragment.SystemDeviceinFragment; -import com.bonait.bnframework.modules.home.fragment.from.fragment.SystemSeasoningsetFragment; -import com.bonait.bnframework.modules.home.fragment.from.fragment.SystemSystemsetFragment; -import com.bonait.bnframework.modules.home.fragment.from.fragment.systeminternetfragment; -import com.qmuiteam.qmui.widget.QMUITopBar; +import com.bonait.bnframework.ViewModel.Adapter.FragmentAdapter; +import com.bonait.bnframework.ViewModel.FragmentViewModel.SystemDeviceinFragment; +import com.bonait.bnframework.ViewModel.FragmentViewModel.SystemSeasoningsetFragment; +import com.bonait.bnframework.ViewModel.FragmentViewModel.SystemSystemsetFragment; +import com.bonait.bnframework.ViewModel.FragmentViewModel.systeminternetfragment; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.QMUIViewPager; diff --git a/app/src/main/java/com/bonait/bnframework/modules/mine/fragment/UserActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/UserActivity.java similarity index 89% rename from app/src/main/java/com/bonait/bnframework/modules/mine/fragment/UserActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/UserActivity.java index 11b50edc..5d147131 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/mine/fragment/UserActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/UserActivity.java @@ -1,63 +1,31 @@ -package com.bonait.bnframework.modules.mine.fragment; +package com.bonait.bnframework.ViewModel.ActivityViewModel; -import androidx.appcompat.app.AppCompatActivity; - -import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.text.InputType; -import android.text.TextUtils; import android.view.View; import android.widget.Button; -import android.widget.EditText; import android.widget.ListView; import com.bonait.bnframework.R; import com.bonait.bnframework.common.base.BaseActivity; import com.bonait.bnframework.common.constant.ConfigName; -import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.db.QueryDB; -import com.bonait.bnframework.common.db.mode.BPA_GOODS; -import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; -import com.bonait.bnframework.common.db.mode.BPA_SILOS; -import com.bonait.bnframework.common.db.mode.BPA_SILOSANDMATERIAL; import com.bonait.bnframework.common.db.mode.BPA_USER; -import com.bonait.bnframework.common.helper.I.IRunT; import com.bonait.bnframework.common.helper.I.MyClickListener; -import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback; -import com.bonait.bnframework.common.message.MessageManager; -import com.bonait.bnframework.common.model.ResAPI; -import com.bonait.bnframework.common.model.mode.ActionJsonMode; -import com.bonait.bnframework.common.model.mode.BatchingInfo; -import com.bonait.bnframework.common.model.mode.BomTechnologyActionInfo; -import com.bonait.bnframework.common.model.mode.CloudGood; -import com.bonait.bnframework.common.model.mode.GoodsTechnology; -import com.bonait.bnframework.common.model.mode.TechnologyAction; -import com.bonait.bnframework.common.model.mode.UpdateBomInfo; -import com.bonait.bnframework.common.model.mode.UpdateCloudGood; -import com.bonait.bnframework.common.oss.OssHelper; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.common.view.AddUserDialog; -import com.bonait.bnframework.common.view.GoodEditDialog; -import com.bonait.bnframework.modules.home.adapter.user_adapter; -import com.google.gson.Gson; -import com.lzy.okgo.OkGo; -import com.lzy.okgo.model.HttpHeaders; -import com.lzy.okgo.model.Response; +import com.bonait.bnframework.ViewModel.Adapter.user_adapter; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; -import okhttp3.MediaType; -import okhttp3.RequestBody; public class UserActivity extends BaseActivity implements MyClickListener { @BindView(R.id.topbar) diff --git a/app/src/main/java/com/bonait/bnframework/modules/welcome/activity/WelcomeActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/WelcomeActivity.java similarity index 96% rename from app/src/main/java/com/bonait/bnframework/modules/welcome/activity/WelcomeActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/WelcomeActivity.java index 2f682f7d..b0f40f5f 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/welcome/activity/WelcomeActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/WelcomeActivity.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.welcome.activity; +package com.bonait.bnframework.ViewModel.ActivityViewModel; import android.Manifest; import android.content.Intent; @@ -6,8 +6,6 @@ import android.os.Bundle; import android.os.Handler; import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.recyclerview.widget.GridLayoutManager; import android.view.KeyEvent; @@ -18,12 +16,10 @@ import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.Constants; import com.bonait.bnframework.common.utils.ScreenUtils; import com.bonait.bnframework.manager.ActivityLifecycleManager; -import com.bonait.bnframework.modules.home.activity.BottomNavigation2Activity; import com.bonait.bnframework.test.TestActivity; import com.lzy.okgo.OkGo; import okhttp3.OkHttpClient; -import pub.devrel.easypermissions.AfterPermissionGranted; import pub.devrel.easypermissions.EasyPermissions; public class WelcomeActivity extends BaseActivity { diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/WhActivity.java b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/WhActivity.java similarity index 91% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/WhActivity.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/WhActivity.java index 13927f9f..5e417328 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/WhActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/ActivityViewModel/WhActivity.java @@ -1,10 +1,10 @@ -package com.bonait.bnframework.modules.home.fragment.from; +package com.bonait.bnframework.ViewModel.ActivityViewModel; import androidx.annotation.NonNull; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.fragment.from.fragment.SystemCsPLCFragment; +import com.bonait.bnframework.ViewModel.FragmentViewModel.SystemCsPLCFragment; import com.google.android.material.bottomnavigation.BottomNavigationView; import androidx.viewpager.widget.ViewPager; @@ -18,11 +18,10 @@ import android.widget.RelativeLayout; import com.bonait.bnframework.R; import com.bonait.bnframework.common.base.BaseActivity; -import com.bonait.bnframework.modules.home.adapter.FragmentAdapter; -import com.bonait.bnframework.modules.home.fragment.from.fragment.SystemCsFltlFragment; -import com.bonait.bnframework.modules.home.fragment.from.fragment.SystemCsControlFragment; -import com.bonait.bnframework.modules.home.fragment.from.fragment.SystemCsMonitorFragment; -import com.qmuiteam.qmui.widget.QMUITopBar; +import com.bonait.bnframework.ViewModel.Adapter.FragmentAdapter; +import com.bonait.bnframework.ViewModel.FragmentViewModel.SystemCsFltlFragment; +import com.bonait.bnframework.ViewModel.FragmentViewModel.SystemCsControlFragment; +import com.bonait.bnframework.ViewModel.FragmentViewModel.SystemCsMonitorFragment; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.QMUIViewPager; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/FragmentAdapter.java b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/FragmentAdapter.java similarity index 94% rename from app/src/main/java/com/bonait/bnframework/modules/home/adapter/FragmentAdapter.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/FragmentAdapter.java index 3b808d75..a21520c5 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/FragmentAdapter.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/FragmentAdapter.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.adapter; +package com.bonait.bnframework.ViewModel.Adapter; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/gongxubuzhou_adapter.java b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/gongxubuzhou_adapter.java similarity index 97% rename from app/src/main/java/com/bonait/bnframework/modules/home/adapter/gongxubuzhou_adapter.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/gongxubuzhou_adapter.java index 8fea4e08..156a3f6b 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/gongxubuzhou_adapter.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/gongxubuzhou_adapter.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.adapter; +package com.bonait.bnframework.ViewModel.Adapter; import android.content.Context; import android.graphics.Color; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/gongxubuzhou_adapter1.java b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/gongxubuzhou_adapter1.java similarity index 97% rename from app/src/main/java/com/bonait/bnframework/modules/home/adapter/gongxubuzhou_adapter1.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/gongxubuzhou_adapter1.java index e60c5627..5df8f77a 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/gongxubuzhou_adapter1.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/gongxubuzhou_adapter1.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.adapter; +package com.bonait.bnframework.ViewModel.Adapter; import android.content.Context; import android.graphics.Color; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/gongxubuzhou_adapter2.java b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/gongxubuzhou_adapter2.java similarity index 97% rename from app/src/main/java/com/bonait/bnframework/modules/home/adapter/gongxubuzhou_adapter2.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/gongxubuzhou_adapter2.java index accc9039..22c34a6e 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/gongxubuzhou_adapter2.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/gongxubuzhou_adapter2.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.adapter; +package com.bonait.bnframework.ViewModel.Adapter; import android.content.Context; import android.view.LayoutInflater; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/good_adapter.java b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/good_adapter.java similarity index 96% rename from app/src/main/java/com/bonait/bnframework/modules/home/adapter/good_adapter.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/good_adapter.java index 01d0c031..8c38617d 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/good_adapter.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/good_adapter.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.adapter; +package com.bonait.bnframework.ViewModel.Adapter; import android.app.Activity; import android.content.Context; @@ -16,21 +16,16 @@ import androidx.recyclerview.widget.RecyclerView; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.common.constant.ConfigName; -import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.image.MyBitmapUtils; -import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.fragment.mode.SectionItem; +import com.bonait.bnframework.ViewModel.CustomView.SectionItem; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import java.math.BigDecimal; -import java.text.DecimalFormat; import java.util.ArrayList; -import java.util.List; public class good_adapter extends RecyclerView.Adapter { //图标 diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/image_sp_adapter.java b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/image_sp_adapter.java similarity index 92% rename from app/src/main/java/com/bonait/bnframework/modules/home/adapter/image_sp_adapter.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/image_sp_adapter.java index f9a9309a..41e2647a 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/image_sp_adapter.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/image_sp_adapter.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.adapter; +package com.bonait.bnframework.ViewModel.Adapter; import android.app.Activity; import android.content.Context; @@ -7,21 +7,17 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.RelativeLayout; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.bonait.bnframework.R; -import com.bonait.bnframework.common.constant.DataBus; -import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.image.MyBitmapUtils; import com.bonait.bnframework.common.utils.AlertDialogUtils; -import com.bonait.bnframework.modules.home.fragment.mode.image_sp; +import com.bonait.bnframework.ViewModel.CustomView.image_sp; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.textview.QMUILinkTextView; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/lc_adapter.java b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/lc_adapter.java similarity index 95% rename from app/src/main/java/com/bonait/bnframework/modules/home/adapter/lc_adapter.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/lc_adapter.java index 4b4a0005..fa61db66 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/lc_adapter.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/lc_adapter.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.adapter; +package com.bonait.bnframework.ViewModel.Adapter; import android.annotation.SuppressLint; import android.app.Activity; @@ -16,7 +16,6 @@ import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.db.res.lcMode; -import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; @@ -87,7 +86,7 @@ public class lc_adapter extends RecyclerView.Adapter { myViewHolder.imageView.setTag(finalKg); myViewHolder.imageView.setImageDrawable(context.getResources().getDrawable(R.mipmap.shuiguan_g)); - ExecuteTheRecipe.WritePLC("料仓"+(position+1)+"手动开关", true, null); +// ExecuteTheRecipe.WritePLC("料仓"+(position+1)+"手动开关", true, null); ToastUtils.info("料仓"+(position+1)+"开关," + finalKg); }else { @@ -95,7 +94,7 @@ public class lc_adapter extends RecyclerView.Adapter { myViewHolder.imageView.setTag(finalKg); myViewHolder.imageView.setImageDrawable(context.getResources().getDrawable(R.mipmap.shuiguan_k2)); - ExecuteTheRecipe.WritePLC("料仓"+(position+1)+"手动开关", false, null); +// ExecuteTheRecipe.WritePLC("料仓"+(position+1)+"手动开关", false, null); ToastUtils.info("料仓"+(position+1)+"开关," + finalKg); } // AlertDialogUtils.showDialog(context, title, message, new QMUIDialogAction.ActionListener() { @@ -129,7 +128,7 @@ public class lc_adapter extends RecyclerView.Adapter { myViewHolder.imageView.setTag(finalKg); myViewHolder.imageView.setImageDrawable(context.getResources().getDrawable(R.mipmap.shuiguan_g)); - ExecuteTheRecipe.WritePLC("料仓"+(position+1)+"手动开关", true, null); + ExecuteTheRecipe.WritePLC("料仓"+(position+1)+"手动开关", true,null); ToastUtils.info("料仓"+(position+1)+"开关," + finalKg); }else { @@ -137,7 +136,7 @@ public class lc_adapter extends RecyclerView.Adapter { myViewHolder.imageView.setTag(finalKg); myViewHolder.imageView.setImageDrawable(context.getResources().getDrawable(R.mipmap.shuiguan_k2)); - ExecuteTheRecipe.WritePLC("料仓"+(position+1)+"手动开关", false, null); + ExecuteTheRecipe.WritePLC("料仓"+(position+1)+"手动开关", false,null); ToastUtils.info("料仓"+(position+1)+"开关," + finalKg); } // AlertDialogUtils.showDialog(context, title, message, new QMUIDialogAction.ActionListener() { @@ -171,7 +170,7 @@ public class lc_adapter extends RecyclerView.Adapter { myViewHolder.imageView.setTag(finalKg); myViewHolder.imageView.setImageDrawable(context.getResources().getDrawable(R.mipmap.shuiguan_g)); - ExecuteTheRecipe.WritePLC("料仓"+(position+1)+"手动开关", true, null); + ExecuteTheRecipe.WritePLC("料仓"+(position+1)+"手动开关", true,null); ToastUtils.info("料仓"+(position+1)+"开关," + finalKg); }else { @@ -179,7 +178,7 @@ public class lc_adapter extends RecyclerView.Adapter { myViewHolder.imageView.setTag(finalKg); myViewHolder.imageView.setImageDrawable(context.getResources().getDrawable(R.mipmap.shuiguan_k2)); - ExecuteTheRecipe.WritePLC("料仓"+(position+1)+"手动开关", false, null); + ExecuteTheRecipe.WritePLC("料仓"+(position+1)+"手动开关", false,null); ToastUtils.info("料仓"+(position+1)+"开关," + finalKg); } // AlertDialogUtils.showDialog(context, title, message, new QMUIDialogAction.ActionListener() { diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/lcsz_adapter.java b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/lcsz_adapter.java similarity index 97% rename from app/src/main/java/com/bonait/bnframework/modules/home/adapter/lcsz_adapter.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/lcsz_adapter.java index 377307d3..ca8e3724 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/lcsz_adapter.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/lcsz_adapter.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.adapter; +package com.bonait.bnframework.ViewModel.Adapter; import android.content.Context; import android.view.LayoutInflater; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/monitor_adapter.java b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/monitor_adapter.java similarity index 98% rename from app/src/main/java/com/bonait/bnframework/modules/home/adapter/monitor_adapter.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/monitor_adapter.java index 32d9e6a1..52b54b1e 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/monitor_adapter.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/monitor_adapter.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.adapter; +package com.bonait.bnframework.ViewModel.Adapter; import android.app.Activity; import android.content.Context; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/process_adapter.java b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/process_adapter.java similarity index 96% rename from app/src/main/java/com/bonait/bnframework/modules/home/adapter/process_adapter.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/process_adapter.java index 2eb86db0..0dfd5bdf 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/process_adapter.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/process_adapter.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.adapter; +package com.bonait.bnframework.ViewModel.Adapter; import android.content.Context; import android.view.LayoutInflater; @@ -15,7 +15,6 @@ import com.bonait.bnframework.R; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_PROCESS; import com.bonait.bnframework.common.db.mode.BPA_PROCESSModel; -import com.bonait.bnframework.common.db.res.lcMode; import com.bonait.bnframework.common.helper.I.MyClickListener; import java.util.ArrayList; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/processchid_adapter.java b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/processchid_adapter.java similarity index 97% rename from app/src/main/java/com/bonait/bnframework/modules/home/adapter/processchid_adapter.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/processchid_adapter.java index 637bda88..f30c7c59 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/processchid_adapter.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/processchid_adapter.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.adapter; +package com.bonait.bnframework.ViewModel.Adapter; import android.content.Context; import android.view.LayoutInflater; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/sp_adapter.java b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/sp_adapter.java similarity index 98% rename from app/src/main/java/com/bonait/bnframework/modules/home/adapter/sp_adapter.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/sp_adapter.java index 62fc6e48..d2d8e5d8 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/sp_adapter.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/sp_adapter.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.adapter; +package com.bonait.bnframework.ViewModel.Adapter; import android.app.Activity; import android.content.Context; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/user_adapter.java b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/user_adapter.java similarity index 98% rename from app/src/main/java/com/bonait/bnframework/modules/home/adapter/user_adapter.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/user_adapter.java index 8a540afb..09f10e4b 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/user_adapter.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/user_adapter.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.adapter; +package com.bonait.bnframework.ViewModel.Adapter; import android.content.Context; import android.view.LayoutInflater; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/wl_adapter.java b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/wl_adapter.java similarity index 97% rename from app/src/main/java/com/bonait/bnframework/modules/home/adapter/wl_adapter.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/wl_adapter.java index 3acc63c9..520b424a 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/wl_adapter.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/Adapter/wl_adapter.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.adapter; +package com.bonait.bnframework.ViewModel.Adapter; import android.content.Context; import android.view.LayoutInflater; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/LocationStatus.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/LocationStatus.java similarity index 59% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/LocationStatus.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/LocationStatus.java index 52bec4ea..70d41e25 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/LocationStatus.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/LocationStatus.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; public enum LocationStatus { diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/MyStatus.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/MyStatus.java similarity index 56% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/MyStatus.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/MyStatus.java index 3d30eb7d..ee6050f2 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/MyStatus.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/MyStatus.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; /** * 状态 diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/QDListSectionAdapter.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/QDListSectionAdapter.java similarity index 96% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/QDListSectionAdapter.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/QDListSectionAdapter.java index 5119feaa..fc7bcfae 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/QDListSectionAdapter.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/QDListSectionAdapter.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import android.content.Context; @@ -7,16 +7,12 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.RelativeLayout; import android.widget.TextView; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ConfigData; -import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.db.QueryDB; -import com.bonait.bnframework.common.db.mode.BPA_GOODS; -import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.image.MyBitmapUtils; import com.bonait.bnframework.common.message.MessageManager; @@ -27,8 +23,6 @@ import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; import com.qmuiteam.qmui.widget.section.QMUIDefaultStickySectionAdapter; import com.qmuiteam.qmui.widget.section.QMUISection; -import java.util.ArrayList; - public class QDListSectionAdapter extends QMUIDefaultStickySectionAdapter { private TextView tvTag ,tvNote,tvAccount,Sc_text,delete_text; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/QDSectionHeaderView.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/QDSectionHeaderView.java similarity index 97% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/QDSectionHeaderView.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/QDSectionHeaderView.java index cc0310c0..be512f75 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/QDSectionHeaderView.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/QDSectionHeaderView.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import android.content.Context; import android.graphics.Color; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SectionHeader.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/SectionHeader.java similarity index 97% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SectionHeader.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/SectionHeader.java index aaa600e7..81212600 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SectionHeader.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/SectionHeader.java @@ -15,7 +15,7 @@ */ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import com.qmuiteam.qmui.widget.section.QMUISection; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SectionItem.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/SectionItem.java similarity index 98% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SectionItem.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/SectionItem.java index 3bf6b217..3b3cb69a 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SectionItem.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/SectionItem.java @@ -15,7 +15,7 @@ */ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import com.qmuiteam.qmui.widget.section.QMUISection; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/add_qupenren.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/add_qupenren.java similarity index 91% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/add_qupenren.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/add_qupenren.java index e3d0dabd..e113c1ac 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/add_qupenren.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/add_qupenren.java @@ -1,9 +1,6 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import android.content.Context; -import android.content.Intent; -import android.os.Handler; -import android.os.Message; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; @@ -18,16 +15,9 @@ import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.DataBus; -import com.bonait.bnframework.common.db.QueryDB; -import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.helper.I.MyClickListener; -import com.bonait.bnframework.common.utils.NetworkUtils; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.fragment.from.DiyUpdateActivity; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; import java.util.concurrent.ConcurrentHashMap; import butterknife.BindView; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/add_silos_message.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/add_silos_message.java similarity index 97% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/add_silos_message.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/add_silos_message.java index e2bb1acc..6888af76 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/add_silos_message.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/add_silos_message.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import android.app.Activity; import android.content.Context; @@ -10,7 +10,6 @@ import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; -import android.widget.RelativeLayout; import android.widget.Spinner; import android.widget.TextView; @@ -18,18 +17,14 @@ import androidx.annotation.Nullable; 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_GOODSRECIPE; 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.IWriteCallBack; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.utils.ToastUtils; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import butterknife.BindView; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_gx.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/fragment_gx.java similarity index 95% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_gx.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/fragment_gx.java index 620da9a2..448e979b 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_gx.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/fragment_gx.java @@ -1,11 +1,8 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; -import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; import android.content.Context; -import android.os.Bundle; import android.text.InputType; import android.util.AttributeSet; import android.view.LayoutInflater; @@ -18,7 +15,6 @@ import android.widget.Spinner; import android.widget.TextView; import com.bonait.bnframework.R; -import com.bonait.bnframework.common.base.BaseFragment; import java.util.ArrayList; import java.util.LinkedHashMap; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_plc.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/fragment_plc.java similarity index 98% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_plc.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/fragment_plc.java index 16225180..bd7a9996 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_plc.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/fragment_plc.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import android.content.Context; import android.text.InputType; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_plc_control.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/fragment_plc_control.java similarity index 99% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_plc_control.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/fragment_plc_control.java index bcbc5be3..eaaa7210 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_plc_control.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/fragment_plc_control.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import android.content.Context; import android.os.Handler; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_silos_cl.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/fragment_silos_cl.java similarity index 82% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_silos_cl.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/fragment_silos_cl.java index 2f4517b7..79ff5a65 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_silos_cl.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/fragment_silos_cl.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import android.content.Context; import android.text.InputType; @@ -18,7 +18,6 @@ import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; import com.bonait.bnframework.common.db.mode.BPA_SILOS; -import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; @@ -59,14 +58,8 @@ public class fragment_silos_cl extends LinearLayout { int val1 = (int)Math.round((Double.parseDouble(text) * 10)); Short val=(short)val1; - ExecuteTheRecipe.WritePLC("料仓" + model.num + "需求值", val, new IWriteCallBack() { - @Override - public void onSuccess() { - ExecuteTheRecipe.WritePLC("料仓" + model.num + "下料",true,null); - } - @Override - public void onFailure(String ErrorMsg) { - } + ExecuteTheRecipe.WritePLC("料仓" + model.num + "需求值", val, ()->{ + ExecuteTheRecipe.WritePLC("料仓" + model.num + "下料",true,null); }); ToastUtils.info("料仓" + model.num+"出料:"+text+"g"); break; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/huoli_control.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/huoli_control.java similarity index 99% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/huoli_control.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/huoli_control.java index 6ac91f82..db5f1f17 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/huoli_control.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/huoli_control.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import android.content.Context; import androidx.annotation.Nullable; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/image_sp.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/image_sp.java similarity index 55% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/image_sp.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/image_sp.java index 4ff60c58..2a2b04b9 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/image_sp.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/image_sp.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; /** * 加载图片 diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/imagebuttom.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/imagebuttom.java similarity index 98% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/imagebuttom.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/imagebuttom.java index 8e67886a..ef0ebfe1 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/imagebuttom.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/imagebuttom.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import android.content.Context; import android.content.res.TypedArray; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/imagebuttom3.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/imagebuttom3.java similarity index 98% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/imagebuttom3.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/imagebuttom3.java index dad7375f..8310b464 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/imagebuttom3.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/imagebuttom3.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import android.content.Context; import android.content.res.TypedArray; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/imagebutton_control.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/imagebutton_control.java similarity index 97% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/imagebutton_control.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/imagebutton_control.java index d124cd7b..45377826 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/imagebutton_control.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/imagebutton_control.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import android.content.Context; import android.content.res.TypedArray; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/item_gx.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/item_gx.java similarity index 78% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/item_gx.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/item_gx.java index 502b69a9..94da7960 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/item_gx.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/item_gx.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; public class item_gx { public String name; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/jingdutiao.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/jingdutiao.java similarity index 95% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/jingdutiao.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/jingdutiao.java index 7d19fd9e..4a92d965 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/jingdutiao.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/jingdutiao.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import android.content.Context; import android.content.res.TypedArray; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/jingdutiao1.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/jingdutiao1.java similarity index 98% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/jingdutiao1.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/jingdutiao1.java index 1ad9737c..9456f863 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/jingdutiao1.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/jingdutiao1.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import android.content.Context; import android.util.AttributeSet; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/newhuoli_control.java b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/newhuoli_control.java similarity index 99% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/newhuoli_control.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/newhuoli_control.java index fd6a8485..c12ac57e 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/newhuoli_control.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/CustomView/newhuoli_control.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.mode; +package com.bonait.bnframework.ViewModel.CustomView; import android.content.Context; import android.util.AttributeSet; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home1Fragment.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home1Fragment.java similarity index 92% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home1Fragment.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home1Fragment.java index 81ebd572..d28e4acb 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home1Fragment.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home1Fragment.java @@ -1,13 +1,10 @@ -package com.bonait.bnframework.modules.home.fragment; +package com.bonait.bnframework.ViewModel.FragmentViewModel; import android.app.Activity; import android.content.Context; import android.content.Intent; -import android.content.res.ColorStateList; -import android.graphics.Canvas; import android.graphics.Color; -import android.graphics.RectF; import android.os.Bundle; import androidx.annotation.NonNull; @@ -17,7 +14,6 @@ import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; import android.os.CountDownTimer; -import android.os.Handler; import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -25,10 +21,7 @@ import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.RelativeLayout; -import android.widget.SeekBar; -import com.aliyun.alink.linksdk.tmp.devicemodel.Event; -import com.aliyun.alink.linksdk.tmp.devicemodel.Property; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.base.BaseFragment; @@ -37,31 +30,18 @@ import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; -import com.bonait.bnframework.common.db.res.StatusMode; -import com.bonait.bnframework.common.helper.ByteHelper; -import com.bonait.bnframework.common.helper.I.IThread; -import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.helper.I.MyClickListener; -import com.bonait.bnframework.common.helper.Json; -import com.bonait.bnframework.common.helper.MessageLog; -import com.bonait.bnframework.common.helper.ThreadManager; -import com.bonait.bnframework.common.modbus.ModbusTcpServer; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.common.view.MyLayoutManager; -import com.bonait.bnframework.modules.home.adapter.lc_adapter; -import com.bonait.bnframework.modules.home.fragment.from.CpxzActivity; -import com.bonait.bnframework.modules.home.fragment.mode.LocationStatus; -import com.bonait.bnframework.modules.home.fragment.mode.MyStatus; -import com.bonait.bnframework.modules.home.fragment.mode.huoli_control; -import com.bonait.bnframework.modules.home.fragment.mode.imagebutton_control; +import com.bonait.bnframework.ViewModel.Adapter.lc_adapter; +import com.bonait.bnframework.ViewModel.ActivityViewModel.CpxzActivity; +import com.bonait.bnframework.ViewModel.CustomView.MyStatus; +import com.bonait.bnframework.ViewModel.CustomView.huoli_control; +import com.bonait.bnframework.ViewModel.CustomView.imagebutton_control; import com.capton.colorfulprogressbar.ColorfulProgressbar; import com.litao.slider.NiftySlider; -import com.litao.slider.SliderEffect; -import com.litao.slider.Utils; -import com.lzy.okgo.OkGo; import com.orhanobut.logger.Logger; -import com.qmuiteam.qmui.widget.QMUITopBar; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; @@ -70,10 +50,7 @@ import com.suke.widget.SwitchButton; import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; -import java.util.Random; import butterknife.BindView; import butterknife.ButterKnife; @@ -403,18 +380,11 @@ public class Home1Fragment extends BaseFragment { // return; // } int jd = (int) nifty_slider2.getValue(); - ExecuteTheRecipe.WritePLC("搅拌速度", jd, new IWriteCallBack() { - @Override - public void onSuccess() { - if (jd == 0) { - ExecuteTheRecipe.WritePLC("搅拌", false, null); - } else { - ExecuteTheRecipe.WritePLC("搅拌", ischick, null); - } - } - - @Override - public void onFailure(String ErrorMsg) { + ExecuteTheRecipe.WritePLC("搅拌速度", jd,()->{ + if (jd == 0) { + ExecuteTheRecipe.WritePLC("搅拌", false, null); + } else { + ExecuteTheRecipe.WritePLC("搅拌", ischick, null); } }); } @@ -431,18 +401,11 @@ public class Home1Fragment extends BaseFragment { // return false; // } int jd = (int) nifty_slider3.getValue(); - ExecuteTheRecipe.WritePLC("转动速度", jd, new IWriteCallBack() { - @Override - public void onSuccess() { - if (jd == 0) { - ExecuteTheRecipe.WritePLC("翻转正转", false, null); - } else { - ExecuteTheRecipe.WritePLC("翻转正转", true, null); - } - } - - @Override - public void onFailure(String ErrorMsg) { + ExecuteTheRecipe.WritePLC("转动速度", jd, ()->{ + if (jd == 0) { + ExecuteTheRecipe.WritePLC("翻转正转", false, null); + } else { + ExecuteTheRecipe.WritePLC("翻转正转", true, null); } }); } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { @@ -464,18 +427,11 @@ public class Home1Fragment extends BaseFragment { // return false; // } int jd = (int) nifty_slider3.getValue(); - ExecuteTheRecipe.WritePLC("转动速度", jd, new IWriteCallBack() { - @Override - public void onSuccess() { - if (jd == 0) { - ExecuteTheRecipe.WritePLC("翻转反转", false, null); - } else { - ExecuteTheRecipe.WritePLC("翻转反转", true, null); - } - } - - @Override - public void onFailure(String ErrorMsg) { + ExecuteTheRecipe.WritePLC("转动速度", jd,()->{ + if (jd == 0) { + ExecuteTheRecipe.WritePLC("翻转反转", false, null); + } else { + ExecuteTheRecipe.WritePLC("翻转反转", true, null); } }); } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home2Fragment.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home2Fragment.java similarity index 86% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home2Fragment.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home2Fragment.java index ada21cbc..027666fa 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home2Fragment.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home2Fragment.java @@ -1,8 +1,6 @@ -package com.bonait.bnframework.modules.home.fragment; +package com.bonait.bnframework.ViewModel.FragmentViewModel; -import static com.bonait.bnframework.MainApplication.getContext; - import android.app.Fragment; import android.content.Context; import android.content.Intent; @@ -10,7 +8,6 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.recyclerview.widget.GridLayoutManager; import android.view.LayoutInflater; import android.view.View; @@ -20,12 +17,10 @@ import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.message.MessageManager; -import com.bonait.bnframework.common.utils.ScreenUtils; -import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.fragment.from.CpActivity; -import com.bonait.bnframework.modules.home.fragment.from.DiyActivity; -import com.bonait.bnframework.modules.home.fragment.from.SzActivity; -import com.bonait.bnframework.modules.home.fragment.from.WhActivity; +import com.bonait.bnframework.ViewModel.ActivityViewModel.CpActivity; +import com.bonait.bnframework.ViewModel.ActivityViewModel.DiyActivity; +import com.bonait.bnframework.ViewModel.ActivityViewModel.SzActivity; +import com.bonait.bnframework.ViewModel.ActivityViewModel.WhActivity; import com.orhanobut.logger.Logger; import com.qmuiteam.qmui.widget.QMUIAppBarLayout; import com.qmuiteam.qmui.widget.QMUICollapsingTopBarLayout; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home3Fragment.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home3Fragment.java similarity index 96% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home3Fragment.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home3Fragment.java index 296670cf..6b5aa083 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home3Fragment.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home3Fragment.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment; +package com.bonait.bnframework.ViewModel.FragmentViewModel; import android.app.Fragment; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home4Fragment.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home4Fragment.java similarity index 86% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home4Fragment.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home4Fragment.java index 60aff659..a283d364 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home4Fragment.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/Home4Fragment.java @@ -1,9 +1,7 @@ -package com.bonait.bnframework.modules.home.fragment; +package com.bonait.bnframework.ViewModel.FragmentViewModel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.content.ContextCompat; import android.content.Context; import android.content.Intent; @@ -11,24 +9,18 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; -import android.widget.TextView; import com.bonait.bnframework.R; -import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.utils.AlertDialogUtils; -import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.manager.ActivityLifecycleManager; -import com.bonait.bnframework.modules.home.fragment.from.BunkerSetupActivity; -import com.bonait.bnframework.modules.home.fragment.from.CpxzActivity; -import com.bonait.bnframework.modules.home.fragment.from.DishTestActivity; -import com.bonait.bnframework.modules.home.fragment.mode.MyStatus; -import com.bonait.bnframework.modules.welcome.activity.LoginActivity; +import com.bonait.bnframework.ViewModel.ActivityViewModel.BunkerSetupActivity; +import com.bonait.bnframework.ViewModel.ActivityViewModel.DishTestActivity; +import com.bonait.bnframework.ViewModel.ActivityViewModel.LoginActivity; import com.orhanobut.logger.Logger; -import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentPR.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/HomeFragmentPR.java similarity index 90% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentPR.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/HomeFragmentPR.java index 9bdd5366..431c7328 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentPR.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/HomeFragmentPR.java @@ -1,10 +1,7 @@ -package com.bonait.bnframework.modules.home.fragment; - -import static com.bonait.bnframework.MainApplication.getContext; +package com.bonait.bnframework.ViewModel.FragmentViewModel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.SearchView; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; @@ -20,7 +17,6 @@ import android.os.Handler; import android.os.Message; import android.view.LayoutInflater; import android.view.View; -import android.widget.RelativeLayout; import android.widget.TextView; import com.bonait.bnframework.R; @@ -28,7 +24,6 @@ import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.constant.ConfigName; -import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODS; @@ -36,22 +31,14 @@ import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.message.MessageLooper; import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.model.mode.CloudGood; -import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.adapter.good_adapter; -import com.bonait.bnframework.modules.home.fragment.from.CookingActivity; -import com.bonait.bnframework.modules.home.fragment.from.CookingSimulatedActivity; -import com.bonait.bnframework.modules.home.fragment.from.DiyUpdate1Activity; -import com.bonait.bnframework.modules.home.fragment.from.DiyUpdateActivity; -import com.bonait.bnframework.modules.home.fragment.mode.SectionHeader; -import com.bonait.bnframework.modules.home.fragment.mode.SectionItem; -import com.bonait.bnframework.modules.home.fragment.mode.add_qupenren; -import com.litao.slider.NiftySlider; +import com.bonait.bnframework.ViewModel.Adapter.good_adapter; +import com.bonait.bnframework.ViewModel.ActivityViewModel.CookingSimulatedActivity; +import com.bonait.bnframework.ViewModel.ActivityViewModel.DiyUpdate1Activity; +import com.bonait.bnframework.ViewModel.CustomView.SectionItem; +import com.bonait.bnframework.ViewModel.CustomView.add_qupenren; import com.orhanobut.logger.Logger; import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.section.QMUISection; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentSBKZ.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/HomeFragmentSBKZ.java similarity index 94% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentSBKZ.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/HomeFragmentSBKZ.java index b5365b89..145f723a 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HomeFragmentSBKZ.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/HomeFragmentSBKZ.java @@ -1,8 +1,7 @@ -package com.bonait.bnframework.modules.home.fragment; +package com.bonait.bnframework.ViewModel.FragmentViewModel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; import android.app.Activity; import android.content.Context; @@ -14,29 +13,21 @@ import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; +import com.bonait.bnframework.HBL.Interface.IRun; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.DataBus; -import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; -import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; -import com.bonait.bnframework.common.db.mode.BPA_SILOS; -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.MouthFacingEnum; import com.bonait.bnframework.common.model.mode.SpeedEnum; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.fragment.mode.imagebuttom3; -import com.bonait.bnframework.modules.home.fragment.mode.newhuoli_control; +import com.bonait.bnframework.ViewModel.CustomView.imagebuttom3; +import com.bonait.bnframework.ViewModel.CustomView.newhuoli_control; import com.orhanobut.logger.Logger; -import java.util.ArrayList; -import java.util.List; - import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; @@ -451,18 +442,11 @@ public class HomeFragmentSBKZ extends BaseFragment { ToastUtils.warning("设置翻炒速度:" + speed.name()); int final_speed = _speed; - ExecuteTheRecipe.WritePLC("搅拌速度", _speed, new IWriteCallBack() { - @Override - public void onSuccess() { - if (final_speed == 0) { - ExecuteTheRecipe.WritePLC("搅拌", false, null); - } else { - ExecuteTheRecipe.WritePLC("搅拌", true, null); - } - } - - @Override - public void onFailure(String ErrorMsg) { + ExecuteTheRecipe.WritePLC("搅拌速度", _speed,()->{ + if (final_speed == 0) { + ExecuteTheRecipe.WritePLC("搅拌", false, null); + } else { + ExecuteTheRecipe.WritePLC("搅拌", true, null); } }); } diff --git a/app/src/main/java/com/bonait/bnframework/modules/mine/fragment/MyFragment.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/MyFragment.java similarity index 98% rename from app/src/main/java/com/bonait/bnframework/modules/mine/fragment/MyFragment.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/MyFragment.java index c45bce8a..66165958 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/mine/fragment/MyFragment.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/MyFragment.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.mine.fragment; +package com.bonait.bnframework.ViewModel.FragmentViewModel; import android.Manifest; import android.content.Context; @@ -19,19 +19,19 @@ import android.widget.TextView; import com.allen.library.SuperTextView; import com.bonait.bnframework.R; +import com.bonait.bnframework.ViewModel.ActivityViewModel.UserActivity; import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.Constants; import com.bonait.bnframework.common.db.QueryDB; -import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.mode.BPA_USER; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.common.utils.UpdateAppUtils; import com.bonait.bnframework.manager.ActivityLifecycleManager; -import com.bonait.bnframework.modules.mine.fragment.from.NoticeActivity; -import com.bonait.bnframework.modules.welcome.activity.LoginActivity; +import com.bonait.bnframework.ViewModel.ActivityViewModel.NoticeActivity; +import com.bonait.bnframework.ViewModel.ActivityViewModel.LoginActivity; import com.orhanobut.logger.Logger; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsControlFragment.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemCsControlFragment.java similarity index 93% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsControlFragment.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemCsControlFragment.java index 5137d80d..dba8d8fa 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsControlFragment.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemCsControlFragment.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.from.fragment; +package com.bonait.bnframework.ViewModel.FragmentViewModel; import android.app.Activity; import android.content.Context; @@ -15,11 +15,9 @@ import com.bonait.bnframework.R; import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; -import com.bonait.bnframework.modules.home.fragment.mode.fragment_plc; -import com.bonait.bnframework.modules.home.fragment.mode.fragment_plc_control; +import com.bonait.bnframework.ViewModel.CustomView.fragment_plc_control; import com.orhanobut.logger.Logger; import com.qmuiteam.qmui.widget.QMUILoadingView; -import com.qmuiteam.qmui.widget.dialog.QMUITipDialog; import java.util.ArrayList; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsFltlFragment.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemCsFltlFragment.java similarity index 87% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsFltlFragment.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemCsFltlFragment.java index ef0e0fb0..99d031b3 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsFltlFragment.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemCsFltlFragment.java @@ -1,27 +1,21 @@ -package com.bonait.bnframework.modules.home.fragment.from.fragment; +package com.bonait.bnframework.ViewModel.FragmentViewModel; import android.app.Activity; import android.content.Context; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; import android.content.ContextWrapper; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; -import android.widget.TextView; import com.bonait.bnframework.R; import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.db.QueryDB; -import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; import com.bonait.bnframework.common.db.mode.BPA_SILOS; -import com.bonait.bnframework.common.myprogress.CustomSeekbar; -import com.bonait.bnframework.common.myprogress.ResponseOnTouch; -import com.bonait.bnframework.modules.home.fragment.mode.fragment_plc_control; -import com.bonait.bnframework.modules.home.fragment.mode.fragment_silos_cl; +import com.bonait.bnframework.ViewModel.CustomView.fragment_silos_cl; import com.orhanobut.logger.Logger; import java.util.ArrayList; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsMonitorFragment.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemCsMonitorFragment.java similarity index 93% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsMonitorFragment.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemCsMonitorFragment.java index 72ad1d97..ce1a0f08 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsMonitorFragment.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemCsMonitorFragment.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.from.fragment; +package com.bonait.bnframework.ViewModel.FragmentViewModel; import android.app.Activity; import android.content.Context; @@ -9,19 +9,16 @@ import androidx.recyclerview.widget.RecyclerView; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; -import android.widget.LinearLayout; import android.widget.TextView; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.constant.ConfigName; -import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.db.res.StatusMode; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.common.view.MyLayoutManager; -import com.bonait.bnframework.modules.home.adapter.lc_adapter; -import com.bonait.bnframework.modules.home.adapter.monitor_adapter; +import com.bonait.bnframework.ViewModel.Adapter.monitor_adapter; import com.orhanobut.logger.Logger; import butterknife.BindView; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsPLCFragment.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemCsPLCFragment.java similarity index 88% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsPLCFragment.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemCsPLCFragment.java index 1b8f8c0f..aae9f335 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsPLCFragment.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemCsPLCFragment.java @@ -1,38 +1,28 @@ -package com.bonait.bnframework.modules.home.fragment.from.fragment; +package com.bonait.bnframework.ViewModel.FragmentViewModel; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.recyclerview.widget.RecyclerView; import android.app.Activity; import android.content.Context; import android.content.ContextWrapper; import android.os.Bundle; -import android.text.InputType; import android.view.LayoutInflater; import android.view.View; -import android.widget.Button; import android.widget.LinearLayout; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.common.base.BaseFragment; -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_PLCADDRESS; -import com.bonait.bnframework.common.modbus.ModbusTcpServer; import com.bonait.bnframework.common.utils.AlertDialogUtils; -import com.bonait.bnframework.common.utils.NetworkUtils; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.fragment.mode.fragment_gx; -import com.bonait.bnframework.modules.home.fragment.mode.fragment_plc; +import com.bonait.bnframework.ViewModel.CustomView.fragment_plc; import com.orhanobut.logger.Logger; import com.qmuiteam.qmui.widget.QMUILoadingView; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.dialog.QMUITipDialog; import java.util.ArrayList; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemDeviceinFragment.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemDeviceinFragment.java similarity index 98% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemDeviceinFragment.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemDeviceinFragment.java index 29ede5b6..175a69c9 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemDeviceinFragment.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemDeviceinFragment.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.from.fragment; +package com.bonait.bnframework.ViewModel.FragmentViewModel; import android.content.Context; import androidx.annotation.NonNull; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSeasoningsetFragment.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemSeasoningsetFragment.java similarity index 98% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSeasoningsetFragment.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemSeasoningsetFragment.java index 92a8810a..f15ea377 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSeasoningsetFragment.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemSeasoningsetFragment.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.from.fragment; +package com.bonait.bnframework.ViewModel.FragmentViewModel; import android.annotation.SuppressLint; import android.content.Context; @@ -33,9 +33,9 @@ import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.NetworkUtils; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.adapter.lcsz_adapter; -import com.bonait.bnframework.modules.home.adapter.process_adapter; -import com.bonait.bnframework.modules.home.adapter.wl_adapter; +import com.bonait.bnframework.ViewModel.Adapter.lcsz_adapter; +import com.bonait.bnframework.ViewModel.Adapter.process_adapter; +import com.bonait.bnframework.ViewModel.Adapter.wl_adapter; import com.orhanobut.logger.Logger; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemSystemsetFragment.java similarity index 99% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemSystemsetFragment.java index 2ccefd15..117a0e49 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/SystemSystemsetFragment.java @@ -1,4 +1,4 @@ -package com.bonait.bnframework.modules.home.fragment.from.fragment; +package com.bonait.bnframework.ViewModel.FragmentViewModel; import android.content.Context; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/systeminternetfragment.java b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/systeminternetfragment.java similarity index 88% rename from app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/systeminternetfragment.java rename to app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/systeminternetfragment.java index 7a073cf7..be912e0c 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/systeminternetfragment.java +++ b/app/src/main/java/com/bonait/bnframework/ViewModel/FragmentViewModel/systeminternetfragment.java @@ -1,56 +1,41 @@ -package com.bonait.bnframework.modules.home.fragment.from.fragment; +package com.bonait.bnframework.ViewModel.FragmentViewModel; import android.content.Context; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; -import android.widget.EditText; import com.bonait.bnframework.R; import com.bonait.bnframework.common.base.BaseFragment; -import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.Constants; -import com.bonait.bnframework.common.db.QueryDB; -import com.bonait.bnframework.common.db.mode.BPA_SYSTEMSET; import com.bonait.bnframework.common.filepicker.PickerManager; import com.bonait.bnframework.common.filepicker.adapter.FilePickerShowAdapter; -import com.bonait.bnframework.common.filepicker.adapter.OnDeleteListener; import com.bonait.bnframework.common.filepicker.adapter.OnFileItemClickListener; import com.bonait.bnframework.common.filepicker.model.FileEntity; import com.bonait.bnframework.common.filepicker.model.FileType; -import com.bonait.bnframework.common.filepicker.util.OpenFile; import com.bonait.bnframework.common.image.utils.LocalCacheUtils; -import com.bonait.bnframework.common.image.utils.MD5Encoder; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.common.view.MyImageDialog; -import com.bonait.bnframework.common.view.MyLayoutManager; -import com.bonait.bnframework.modules.home.fragment.from.FileActivity; -import com.bonait.bnframework.modules.home.fragment.mode.image_sp; +import com.bonait.bnframework.ViewModel.ActivityViewModel.FileActivity; import com.orhanobut.logger.Logger; -import com.qmuiteam.qmui.arch.QMUIFragment; import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; -import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; -import pub.devrel.easypermissions.EasyPermissions; /** * 资源管理 diff --git a/app/src/main/java/com/bonait/bnframework/business/ConfigData.java b/app/src/main/java/com/bonait/bnframework/business/ConfigData.java index 6564b79d..6c607036 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ConfigData.java +++ b/app/src/main/java/com/bonait/bnframework/business/ConfigData.java @@ -8,7 +8,9 @@ import android.os.Message; import androidx.annotation.NonNull; +import com.bonait.bnframework.HBL.Interface.IRunT; import com.bonait.bnframework.R; +import com.bonait.bnframework.Service.ModbusHelper; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.constant.MessageName; @@ -23,14 +25,10 @@ import com.bonait.bnframework.common.db.mode.BPA_PROCESSModel; import com.bonait.bnframework.common.db.mode.BPA_SYSTEMSET; import com.bonait.bnframework.common.db.mode.Res_PLCADDRESS; import com.bonait.bnframework.common.helper.ConfigUtil; -import com.bonait.bnframework.common.helper.I.IRun; -import com.bonait.bnframework.common.helper.I.IRunT; import com.bonait.bnframework.common.helper.Json; import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback; import com.bonait.bnframework.common.image.utils.LocalCacheUtils; import com.bonait.bnframework.common.message.MessageManager; -import com.bonait.bnframework.common.modbus.ModbusTcpHelper; -import com.bonait.bnframework.common.modbus.ModbusTcpServer; import com.bonait.bnframework.common.model.ResAPI; import com.bonait.bnframework.common.model.mode.ActionJsonMode; import com.bonait.bnframework.common.model.mode.BPA_GoodsAttributeValue; @@ -1029,19 +1027,19 @@ public class ConfigData { */ public void RevertPLCProcess() { try { - List plcaddresses = ConfigName.getInstance().PlcAddress_大炒; - List processTS = ConfigName.getInstance().Process_大炒; - - if (ConfigName.getInstance().versionSelectionEnum.equals("大炒版本")) { - plcaddresses = ConfigName.getInstance().PlcAddress_大炒; - processTS = ConfigName.getInstance().Process_大炒; - } else if (ConfigName.getInstance().versionSelectionEnum.equals("大炒自动投料版本")) { - plcaddresses = ConfigName.getInstance().PlcAddress_大炒自动投料; - processTS = ConfigName.getInstance().Process_大炒自动投料; - } else if (ConfigName.getInstance().versionSelectionEnum.equals("小炒版本")) { - plcaddresses = ConfigName.getInstance().PlcAddress_小炒; - processTS = ConfigName.getInstance().Process_小炒; - } +// List plcaddresses = ConfigName.getInstance().PlcAddress_大炒; + List processTS = ConfigName.getInstance().Process_桌面小炒; + +// if (ConfigName.getInstance().versionSelectionEnum.equals("大炒版本")) { +// plcaddresses = ConfigName.getInstance().PlcAddress_大炒; +// processTS = ConfigName.getInstance().Process_大炒; +// } else if (ConfigName.getInstance().versionSelectionEnum.equals("大炒自动投料版本")) { +// plcaddresses = ConfigName.getInstance().PlcAddress_大炒自动投料; +// processTS = ConfigName.getInstance().Process_大炒自动投料; +// } else if (ConfigName.getInstance().versionSelectionEnum.equals("小炒版本")) { +// plcaddresses = ConfigName.getInstance().PlcAddress_小炒; +// processTS = ConfigName.getInstance().Process_小炒; +// } //region 恢复PLC ArrayList arrayList = QueryDB.GetPlcaddressALL(); @@ -1049,16 +1047,16 @@ public class ConfigData { QueryDB.DeletePlcaddress(item); } int k = 1; - for (Res_PLCADDRESS item : plcaddresses) { - BPA_PLCADDRESS plc = new BPA_PLCADDRESS(); - plc.name = item.name; - plc.address = item.address; - plc.isread = item.isread; - plc.iswrite = item.iswrite; - plc.sort = k; - k++; - QueryDB.AddPlcaddress(plc); - } +// for (Res_PLCADDRESS item : plcaddresses) { +// BPA_PLCADDRESS plc = new BPA_PLCADDRESS(); +// plc.name = item.name; +// plc.address = item.address; +// plc.isread = item.isread; +// plc.iswrite = item.iswrite; +// plc.sort = k; +// k++; +// QueryDB.AddPlcaddress(plc); +// } //endregion //region 恢复工序 @@ -1101,27 +1099,13 @@ public class ConfigData { //region PLC初始化 - /** - * 连接PLC - */ - public void ConnectPLC() { - new Thread(new Runnable() { - @Override - public void run() { - try { - ModbusTcpServer.get().Connect(); - } catch (Exception e) { - } - } - }).start(); - } /** * 关闭PLC */ public void ColsePLC() { - ModbusTcpHelper.get().release();//释放modbus + ModbusHelper.get().DisConnect();//释放modbus ConfigName.getInstance().PlcIsConnect = false; } 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 b941613f..bfa41fb0 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java +++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java @@ -9,35 +9,28 @@ import android.util.Log; import androidx.annotation.NonNull; +import com.bonait.bnframework.HBL.Interface.IRun; +import com.bonait.bnframework.HBL.Interface.IRunT; +import com.bonait.bnframework.HBL.Thread.IThread; +import com.bonait.bnframework.HBL.Thread.ThreadManager; +import com.bonait.bnframework.Service.ModbusHelper; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; -import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; import com.bonait.bnframework.common.db.mode.BPA_SILOS; import com.bonait.bnframework.common.helper.ByteHelper; -import com.bonait.bnframework.common.helper.I.IRun; -import com.bonait.bnframework.common.helper.I.IRunT; -import com.bonait.bnframework.common.helper.I.IThread; -import com.bonait.bnframework.common.helper.I.IWriteCallBack; -import com.bonait.bnframework.common.helper.ThreadManager; -import com.bonait.bnframework.common.modbus.ModbusTcpServer; -import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.fragment.mode.LocationStatus; -import com.bonait.bnframework.modules.home.fragment.mode.MyStatus; +import com.bonait.bnframework.ViewModel.CustomView.MyStatus; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; import java.util.ArrayList; import java.util.HashMap; -import java.util.IdentityHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import kotlin.UShort; - /** * 执行配方 */ @@ -213,10 +206,10 @@ public class ExecuteTheRecipe { if ((System.currentTimeMillis() - a) > 1000 * whileTime) { break; } else { - Object sb = ReadPLC(name);// ListeningValue.get(name); - if (sb != null) { - IsComplete[0] = (boolean) (sb); - } +// Object sb = ReadPLC(name);// ListeningValue.get(name); +// if (sb != null) { +// IsComplete[0] = (boolean) (sb); +// } } Thread.sleep(100);//10 *6 } @@ -310,20 +303,12 @@ public class ExecuteTheRecipe { ToastUtils.info("准备写入PLC仓号需求:" + silos.num + "," + val / 10.0); String name = "料仓" + silos.num + "下料完成"; - ExecuteTheRecipe.WritePLC(name, false, null); +// ExecuteTheRecipe.WritePLC(name, false, null); final boolean[] IsComplete = {false}; - - WritePLC("料仓" + silos.num + "需求值", val, new IWriteCallBack() { - @Override - public void onSuccess() { - BottomClick("料仓" + silos.num + "下料"); - IsComplete[0] = true; - } - - @Override - public void onFailure(String ErrorMsg) { - } + WritePLC("料仓" + silos.num + "需求值", val,()->{ + BottomClick("料仓" + silos.num + "下料"); + IsComplete[0] = true; }); long a = System.currentTimeMillis(); while (!IsComplete[0]) { @@ -365,18 +350,12 @@ public class ExecuteTheRecipe { if (ExecuteCurrentOperation != null) { ExecuteCurrentOperation.Run("搅拌" + "|" + writeValue); } - WritePLC(key, writeValue, new IWriteCallBack() { - @Override - public void onSuccess() { - if (writeValue == 0) { - WritePLC("搅拌", false, null); - } else { - WritePLC("搅拌", true, null); - } - } - @Override - public void onFailure(String ErrorMsg) { + WritePLC(key, writeValue, ()->{ + if (writeValue == 0) { + WritePLC("搅拌", false, null); + } else { + WritePLC("搅拌", true, null); } }); } @@ -405,7 +384,7 @@ public class ExecuteTheRecipe { val = Integer.parseInt(value); } else if (key.contains("速度")) { int writeValue = GetMXValue(key, value); - WritePLC(key, writeValue, null); + WritePLC(key, writeValue,null); } } @@ -499,7 +478,7 @@ public class ExecuteTheRecipe { ToastUtils.info("工序:手动投料," + name + "," + zl); String title = "手动投料-温馨提示!"; String message = "客官请投入主料,[" + name + "]重量" + zl + "g,投入后点击[确定]继续流程!"; - ExecuteTheRecipe.WritePLC("暂停开关", true, null); +// ExecuteTheRecipe.WritePLC("暂停开关", true, null); final boolean[] IsComplete = {false}; Activity activity = findActivity(context); @@ -532,7 +511,7 @@ public class ExecuteTheRecipe { while (!IsComplete[0]) { Thread.sleep(100);//10 *6 } - ExecuteTheRecipe.WritePLC("暂停开关", false, null); +// ExecuteTheRecipe.WritePLC("暂停开关", false, null); ToastUtils.info("确定完成,继续制作!"); } else { //自动投料 @@ -670,20 +649,13 @@ public class ExecuteTheRecipe { if (ExecuteCurrentOperation != null) { ExecuteCurrentOperation.Run("加热" + "|" + writeValue); } - WritePLC(key, writeValue, new IWriteCallBack() { - @Override - public void onSuccess() { - if (writeValue == 0) { - ConfigName.getInstance().IsOpenHuoLi = false; - WritePLC("加热", false, null); - } else { - ConfigName.getInstance().IsOpenHuoLi = true; - WritePLC("加热", true, null); - } - } - - @Override - public void onFailure(String ErrorMsg) { + WritePLC(key, writeValue, ()->{ + if (writeValue == 0) { + ConfigName.getInstance().IsOpenHuoLi = false; + WritePLC("加热", false, null); + } else { + ConfigName.getInstance().IsOpenHuoLi = true; + WritePLC("加热", true, null); } }); } @@ -718,7 +690,7 @@ public class ExecuteTheRecipe { ExecuteCurrentOperation.Run("加水" + "|" + val); } if (val > 0) { - WritePLC("炒锅抽水", true, null); + WritePLC("炒锅抽水", true,null); new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { @@ -860,20 +832,13 @@ public class ExecuteTheRecipe { */ public static void Write_PLC_HuoLI(int data) { try { - WritePLC("加热功率", data, new IWriteCallBack() { - @Override - public void onSuccess() { - if (data == 0) { - ConfigName.getInstance().IsOpenHuoLi = false; - WritePLC("加热", false, null); - } else { - ConfigName.getInstance().IsOpenHuoLi = true; - WritePLC("加热", true, null); - } - } - - @Override - public void onFailure(String ErrorMsg) { + WritePLC("加热功率", data, ()->{ + if (data == 0) { + ConfigName.getInstance().IsOpenHuoLi = false; + WritePLC("加热", false, null); + } else { + ConfigName.getInstance().IsOpenHuoLi = true; + WritePLC("加热", true, null); } }); ToastUtils.info("火力按钮点击,当前级别:" + data); @@ -917,7 +882,7 @@ public class ExecuteTheRecipe { }).start(); - ThreadManager.Get().StartLong("PLC设备数据监听", true, new IThread() { + ThreadManager.get().StartLong("PLC设备数据监听", true, new IThread() { @Override public void Run() throws InterruptedException { try { @@ -941,11 +906,6 @@ public class ExecuteTheRecipe { } Thread.sleep(100); } - - @Override - public void RunComplete() throws InterruptedException { - - } }); } //endregion @@ -958,20 +918,20 @@ public class ExecuteTheRecipe { * @param name * @param value */ - public static void WritePLC(String name, Object value, IWriteCallBack callback) { + public static void WritePLC(String name, Object value, IRun callback) { try { if (ConfigName.getInstance().PLC_Address.containsKey(name)) { BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); if (!plcaddress.address.isEmpty() && ConfigName.getInstance().PlcIsConnect) { if (plcaddress.address.toUpperCase().startsWith("VD"))//int { - ModbusTcpServer.get().WriteInt(plcaddress.address, (int) value, callback); +// ModbusTcpServer.get().WriteInt(plcaddress.address, (int) value, callback); } else if (plcaddress.address.toUpperCase().startsWith("M"))//bool { - ModbusTcpServer.get().WriteBool(plcaddress.address, (boolean) value, callback); +// ModbusTcpServer.get().WriteBool(plcaddress.address, (boolean) value, callback); } else if (plcaddress.address.toUpperCase().startsWith("VW"))//short { - ModbusTcpServer.get().WriteShort(plcaddress.address, Short.parseShort(value.toString()), callback); +// ModbusTcpServer.get().WriteShort(plcaddress.address, Short.parseShort(value.toString()), callback); } } } @@ -996,20 +956,19 @@ public class ExecuteTheRecipe { if (!plcaddress.address.isEmpty() && ConfigName.getInstance().PlcIsConnect) { if (plcaddress.address.toUpperCase().startsWith("VD"))//int { - - ModbusTcpServer.get().ReadInt(plcaddress.address, 1, ints -> { - ReturnsVariable[0] = ints[0]; - }); +// ModbusTcpServer.get().ReadInt(plcaddress.address, 1, ints -> { +// ReturnsVariable[0] = ints[0]; +// }); } else if (plcaddress.address.toUpperCase().startsWith("M"))//bool { - ModbusTcpServer.get().ReadBool(plcaddress.address, 1, val -> { - ReturnsVariable[0] = val[0]; - }); +// ModbusTcpServer.get().ReadBool(plcaddress.address, 1, val -> { +// ReturnsVariable[0] = val[0]; +// }); } else if (plcaddress.address.toUpperCase().startsWith("VW"))//short { - ModbusTcpServer.get().ReadShort(plcaddress.address, 1, val -> { - ReturnsVariable[0] = val[0]; - }); +// ModbusTcpServer.get().ReadShort(plcaddress.address, 1, val -> { +// ReturnsVariable[0] = val[0]; +// }); } } } @@ -1075,19 +1034,19 @@ public class ExecuteTheRecipe { public static void ReadPLCStatus() { try { if (ConfigName.getInstance().PlcIsConnect) { - ModbusTcpServer.get().ReadStatus("VW354", 1, data -> { - for (int i = 0; i < data.length; i++) { - byte status = data[i];//0x92 - IoStatus.put(i * 8 + 0, ByteHelper.getBit(status, 0) == 1); - IoStatus.put(i * 8 + 1, ByteHelper.getBit(status, 1) == 1); - IoStatus.put(i * 8 + 2, ByteHelper.getBit(status, 2) == 1); - IoStatus.put(i * 8 + 3, ByteHelper.getBit(status, 3) == 1); - IoStatus.put(i * 8 + 4, ByteHelper.getBit(status, 4) == 1); - IoStatus.put(i * 8 + 5, ByteHelper.getBit(status, 5) == 1); - IoStatus.put(i * 8 + 6, ByteHelper.getBit(status, 6) == 1); - IoStatus.put(i * 8 + 7, ByteHelper.getBit(status, 7) == 1); - } - }); +// ModbusTcpServer.get().ReadStatus("VW354", 1, data -> { +// for (int i = 0; i < data.length; i++) { +// byte status = data[i];//0x92 +// IoStatus.put(i * 8 + 0, ByteHelper.getBit(status, 0) == 1); +// IoStatus.put(i * 8 + 1, ByteHelper.getBit(status, 1) == 1); +// IoStatus.put(i * 8 + 2, ByteHelper.getBit(status, 2) == 1); +// IoStatus.put(i * 8 + 3, ByteHelper.getBit(status, 3) == 1); +// IoStatus.put(i * 8 + 4, ByteHelper.getBit(status, 4) == 1); +// IoStatus.put(i * 8 + 5, ByteHelper.getBit(status, 5) == 1); +// IoStatus.put(i * 8 + 6, ByteHelper.getBit(status, 6) == 1); +// IoStatus.put(i * 8 + 7, ByteHelper.getBit(status, 7) == 1); +// } +// }); } } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); @@ -1110,21 +1069,21 @@ public class ExecuteTheRecipe { TempBool = false;//闭合 } - Object tempkg = ExecuteTheRecipe.ReadPLC("温控开关"); - if (tempkg != null) { - boolean kg = (boolean) tempkg; - if (TempBool) //设置断开 - { - if (kg == false) { - ExecuteTheRecipe.WritePLC("温控开关", true, null);//断开 - } - } else //设置闭合 - { - if (kg) { - ExecuteTheRecipe.WritePLC("温控开关", false, null);//闭合 - } - } - } +// Object tempkg = ExecuteTheRecipe.ReadPLC("温控开关"); +// if (tempkg != null) { +// boolean kg = (boolean) tempkg; +// if (TempBool) //设置断开 +// { +// if (kg == false) { +// ExecuteTheRecipe.WritePLC("温控开关", true, null);//断开 +// } +// } else //设置闭合 +// { +// if (kg) { +// ExecuteTheRecipe.WritePLC("温控开关", false, null);//闭合 +// } +// } +// } } //endregion diff --git a/app/src/main/java/com/bonait/bnframework/business/MainInit.java b/app/src/main/java/com/bonait/bnframework/business/MainInit.java index c524be0a..b5f2fbca 100644 --- a/app/src/main/java/com/bonait/bnframework/business/MainInit.java +++ b/app/src/main/java/com/bonait/bnframework/business/MainInit.java @@ -22,10 +22,7 @@ import com.bonait.bnframework.common.db.mode.BPA_USER; import com.bonait.bnframework.common.db.res.AlertLogEnum; import com.bonait.bnframework.common.db.res.UserLogEnum; import com.bonait.bnframework.common.helper.CrashHandler; -import com.bonait.bnframework.common.helper.I.IMessageLogNotify; -import com.bonait.bnframework.common.helper.MessageLog; import com.bonait.bnframework.common.helper.SdCart; -import com.bonait.bnframework.common.modbus.ModbusTcpHelper; import com.bonait.bnframework.common.notification.MainNotification; import com.bonait.bnframework.common.utils.AppUtils; import com.bonait.bnframework.common.utils.NetworkUtils; @@ -217,7 +214,7 @@ public class MainInit { //10个料仓 if (QueryDB.GetSilosALL().size() == 0) { - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 11; i++) { BPA_SILOS silo = new BPA_SILOS(); silo.id = java.util.UUID.randomUUID().toString(); silo.num = i + 1; @@ -250,71 +247,71 @@ public class MainInit { * 初始化消息日志接收打印 */ public static void InitMsgLog(){ - MessageLog.MsgNotify = new IMessageLogNotify() { - @Override - public void ErrorMsg(String msg) { - if(msg.contains("msg:com.serotonin.modbus4j.exception")) - { - ModbusTcpHelper.get().release();//释放modbus - ConfigName.getInstance().PlcIsConnect=false; - - BPA_ALERTLOG log = new BPA_ALERTLOG(); - log.userID = ConfigName.getInstance().user.userID; - log.type=4; - log.text = msg+"程序断开PLC,准备重连机制..."; - QueryDB.AddAlertlog(log); - } - } - @Override - public void InfoMsg(String msg) { - Log.i("Info", msg); - - } - @Override - public void WarnMsg(String msg) { - Log.w("Warn", msg); - } - @Override - public void UserMsg(UserLogEnum type, String msg) { - BPA_LOG log = new BPA_LOG(); - log.userID = ConfigName.getInstance().user.userID; - switch (type.toString()) - { - case "登录日志":log.type=1; - break; - case "角色操作日志":log.type=2; - break; - case "数据接收":log.type=3; - break; - case "上传日志":log.type=4; - break; - case "订单处理日志":log.type=5; - break; - } - log.text = msg; - QueryDB.Addlog(log); - } - - @Override - public void AlertMsg(AlertLogEnum type, String msg) { - BPA_ALERTLOG log = new BPA_ALERTLOG(); - log.userID = ConfigName.getInstance().user.userID; - switch (type.toString()) - { - case "异常订单未制作日志":log.type=1; - break; - case "料仓缺料日志":log.type=2; - break; - case "传感器异常日志":log.type=3; - break; - case "其他":log.type=4; - break; - } - log.text = msg; - - QueryDB.AddAlertlog(log); - } - }; +// MessageLog.MsgNotify = new IMessageLogNotify() { +// @Override +// public void ErrorMsg(String msg) { +// if(msg.contains("msg:com.serotonin.modbus4j.exception")) +// { +// ModbusTcpHelper.get().release();//释放modbus +// ConfigName.getInstance().PlcIsConnect=false; +// +// BPA_ALERTLOG log = new BPA_ALERTLOG(); +// log.userID = ConfigName.getInstance().user.userID; +// log.type=4; +// log.text = msg+"程序断开PLC,准备重连机制..."; +// QueryDB.AddAlertlog(log); +// } +// } +// @Override +// public void InfoMsg(String msg) { +// Log.i("Info", msg); +// +// } +// @Override +// public void WarnMsg(String msg) { +// Log.w("Warn", msg); +// } +// @Override +// public void UserMsg(UserLogEnum type, String msg) { +// BPA_LOG log = new BPA_LOG(); +// log.userID = ConfigName.getInstance().user.userID; +// switch (type.toString()) +// { +// case "登录日志":log.type=1; +// break; +// case "角色操作日志":log.type=2; +// break; +// case "数据接收":log.type=3; +// break; +// case "上传日志":log.type=4; +// break; +// case "订单处理日志":log.type=5; +// break; +// } +// log.text = msg; +// QueryDB.Addlog(log); +// } +// +// @Override +// public void AlertMsg(AlertLogEnum type, String msg) { +// BPA_ALERTLOG log = new BPA_ALERTLOG(); +// log.userID = ConfigName.getInstance().user.userID; +// switch (type.toString()) +// { +// case "异常订单未制作日志":log.type=1; +// break; +// case "料仓缺料日志":log.type=2; +// break; +// case "传感器异常日志":log.type=3; +// break; +// case "其他":log.type=4; +// break; +// } +// log.text = msg; +// +// QueryDB.AddAlertlog(log); +// } +// }; } /** * 内存泄漏检测,根据flag来判断要不要初始化 diff --git a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java index 0c55a490..fee1e126 100644 --- a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java +++ b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java @@ -804,6 +804,23 @@ public class ConfigName { add(new ProcessT("出菜", Arrays.asList("等待(秒)"))); }}; + + /** + * 小炒工序模型 + */ + public List Process_桌面小炒 = new ArrayList() {{ + add(new ProcessT("加热", Arrays.asList("加热档位","加热控制", "延迟(秒)"))); + add(new ProcessT("液体料", new ArrayList<>())); + add(new ProcessT("主料", Arrays.asList("主料名称", "主料位置","烹饪(秒)"))); + add(new ProcessT("升降", Arrays.asList("升降控制", "延迟(秒)"))); + add(new ProcessT("搅拌", Arrays.asList("搅拌控制", "延迟(秒)"))); + add(new ProcessT("勾芡", Arrays.asList("时长(秒)"))); + add(new ProcessT("加水", Arrays.asList("时长(秒)"))); + add(new ProcessT("延迟", Arrays.asList("延迟(秒)"))); + add(new ProcessT("出菜", Arrays.asList("等待(秒)"))); + }}; + + /** * 根据名称获取变量 * @@ -811,22 +828,36 @@ public class ConfigName { * @return */ public String GetProcessTypeVal(String item) { +// String data = ""; +// if (item.equals("搅拌动作")) { +// data = "正转反转、一直正转、一直反转"; +// } else if (item.equals("位置动作")) { +// data = "原点位、出餐启动、倒菜位、抽料位、清洗位、炒菜位1、炒菜位2、炒菜位3"; +// } else if (item.equals("投料动作")) { +// //data = "投出抖动三次、投出等待三秒、直接投出、手动投料"; +// data = "投出等待三秒、直接投出、手动投料"; +// } else if (item.equals("主料位置")) { +// data = "1号位、2号位、3号位、4号位、5号位"; +// } else if (item.equals("正转速度") || item.equals("反转速度") || item.equals("转动速度") || item.equals("搅拌速度")) { +// data = "停止、最低、低速、中速、高速、最高、极高"; +// } else if (item.equals("加热功率") || item.equals("热锅功率")) { +// data = "停止、一档、二档、三档、四档、五档、六档、七档、八档"; +// } +// return data; + String data = ""; - if (item.equals("搅拌动作")) { - data = "正转反转、一直正转、一直反转"; - } else if (item.equals("位置动作")) { - data = "原点位、出餐启动、倒菜位、抽料位、清洗位、炒菜位1、炒菜位2、炒菜位3"; - } else if (item.equals("投料动作")) { - //data = "投出抖动三次、投出等待三秒、直接投出、手动投料"; - data = "投出等待三秒、直接投出、手动投料"; + if (item.equals("加热控制")) { + data = "启动加热、停止加热"; } else if (item.equals("主料位置")) { - data = "1号位、2号位、3号位、4号位"; - } else if (item.equals("正转速度") || item.equals("反转速度") || item.equals("转动速度") || item.equals("搅拌速度")) { - data = "停止、最低、低速、中速、高速、最高、极高"; - } else if (item.equals("加热功率") || item.equals("热锅功率")) { - data = "停止、一档、二档、三档、四档、五档、六档、七档、八档"; + data = "1号位、2号位、3号位、4号位、5号位"; + } else if (item.equals("升降控制") ) { + data = "上升、下降"; + } else if (item.equals("搅拌控制") ) { + data = "启动搅拌、停止搅拌"; } return data; + + } /** @@ -1024,6 +1055,8 @@ public class ConfigName { put(1, "未设置"); put(2, "未设置"); put(3, "未设置"); + put(4, "未设置"); + put(5, "未设置"); }}; //endregion } diff --git a/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java b/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java index be3b5706..e679cb20 100644 --- a/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java +++ b/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java @@ -1,33 +1,19 @@ package com.bonait.bnframework.common.constant; -import android.content.Intent; - -import com.bonait.bnframework.R; +import com.bonait.bnframework.HBL.Interface.IRun; import com.bonait.bnframework.common.db.QueryDB; -import com.bonait.bnframework.common.db.mode.BPA_ALERTLOG; import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; -import com.bonait.bnframework.common.db.mode.BPA_LOG; import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.mode.BPA_SILOS; -import com.bonait.bnframework.common.db.mode.BPA_SUBORDER; -import com.bonait.bnframework.common.db.res.MakeStatus; -import com.bonait.bnframework.common.db.res.ResGoodsMake; -import com.bonait.bnframework.common.db.res.ResGoodsRecipe; -import com.bonait.bnframework.common.db.res.StatusMode; import com.bonait.bnframework.common.db.res.lcMode; -import com.bonait.bnframework.common.helper.I.IRun; -import com.bonait.bnframework.common.helper.I.IRunT; import com.bonait.bnframework.common.helper.I.MyClickListener; -import com.bonait.bnframework.common.helper.mode.OrderA; -import com.bonait.bnframework.common.helper.mode.ResultA; -import com.bonait.bnframework.modules.home.adapter.lc_adapter; -import com.bonait.bnframework.modules.home.adapter.sp_adapter; +import com.bonait.bnframework.ViewModel.Adapter.lc_adapter; +import com.bonait.bnframework.ViewModel.Adapter.sp_adapter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** diff --git a/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_CALIBRATION_PAR.java b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_CALIBRATION_PAR.java new file mode 100644 index 00000000..e7190ac7 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_CALIBRATION_PAR.java @@ -0,0 +1,18 @@ +package com.bonait.bnframework.common.db.mode; + +public class BPA_CALIBRATION_PAR extends ModeBase { + public String Name; + public short InputMax; + public short InputMin; + public short OutMax; + public short OutMin; + + public BPA_CALIBRATION_PAR() {} + public BPA_CALIBRATION_PAR(String name, short inputMax, short inputMin, short outMax, short outMin) { + Name = name; + InputMax = inputMax; + InputMin = inputMin; + OutMax = outMax; + OutMin = outMin; + } +} diff --git a/app/src/main/java/com/bonait/bnframework/common/filepicker/adapter/FilePickerShowAdapter.java b/app/src/main/java/com/bonait/bnframework/common/filepicker/adapter/FilePickerShowAdapter.java index 80c83626..e8087309 100644 --- a/app/src/main/java/com/bonait/bnframework/common/filepicker/adapter/FilePickerShowAdapter.java +++ b/app/src/main/java/com/bonait/bnframework/common/filepicker/adapter/FilePickerShowAdapter.java @@ -14,12 +14,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.bonait.bnframework.R; import com.bonait.bnframework.common.filepicker.model.FileEntity; import com.bonait.bnframework.common.filepicker.util.FileUtils; -import com.bonait.bnframework.common.image.MyBitmapUtils; -import com.bonait.bnframework.common.utils.AlertDialogUtils; -import com.bonait.bnframework.modules.home.adapter.image_sp_adapter; import com.bumptech.glide.Glide; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; -import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; import java.io.File; import java.util.ArrayList; diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/I/IMessageLogNotify.java b/app/src/main/java/com/bonait/bnframework/common/helper/I/IMessageLogNotify.java deleted file mode 100644 index 34407eb8..00000000 --- a/app/src/main/java/com/bonait/bnframework/common/helper/I/IMessageLogNotify.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.bonait.bnframework.common.helper.I; - -import com.bonait.bnframework.common.db.res.AlertLogEnum; -import com.bonait.bnframework.common.db.res.UserLogEnum; - -public interface IMessageLogNotify { - void ErrorMsg(String msg); - void InfoMsg(String msg); - void WarnMsg(String msg); - void UserMsg(UserLogEnum type, String msg); - void AlertMsg(AlertLogEnum type, String msg); - -} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/I/IReadCallBack.java b/app/src/main/java/com/bonait/bnframework/common/helper/I/IReadCallBack.java deleted file mode 100644 index 11db2f28..00000000 --- a/app/src/main/java/com/bonait/bnframework/common/helper/I/IReadCallBack.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.bonait.bnframework.common.helper.I; - -public interface IReadCallBack { - void onSuccess(T t); -} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/I/IRun.java b/app/src/main/java/com/bonait/bnframework/common/helper/I/IRun.java deleted file mode 100644 index 04925c29..00000000 --- a/app/src/main/java/com/bonait/bnframework/common/helper/I/IRun.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.bonait.bnframework.common.helper.I; - -public interface IRun { - void Run(); -} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/I/IThread.java b/app/src/main/java/com/bonait/bnframework/common/helper/I/IThread.java deleted file mode 100644 index 84caa447..00000000 --- a/app/src/main/java/com/bonait/bnframework/common/helper/I/IThread.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.bonait.bnframework.common.helper.I; - -public interface IThread { - void Run() throws InterruptedException; - - void RunComplete() throws InterruptedException; -} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/I/IWriteCallBack.java b/app/src/main/java/com/bonait/bnframework/common/helper/I/IWriteCallBack.java deleted file mode 100644 index e28d4d67..00000000 --- a/app/src/main/java/com/bonait/bnframework/common/helper/I/IWriteCallBack.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.bonait.bnframework.common.helper.I; - -public interface IWriteCallBack { - void onSuccess(); - - void onFailure(String ErrorMsg); -} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/MQTT.java b/app/src/main/java/com/bonait/bnframework/common/helper/MQTT.java index 2c41d619..1b82339a 100644 --- a/app/src/main/java/com/bonait/bnframework/common/helper/MQTT.java +++ b/app/src/main/java/com/bonait/bnframework/common/helper/MQTT.java @@ -5,9 +5,10 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; +import com.bonait.bnframework.HBL.Interface.IRun; +import com.bonait.bnframework.HBL.Logs.MessageLog; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.helper.I.IMessage; -import com.bonait.bnframework.common.helper.I.IRun; import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; import org.eclipse.paho.client.mqttv3.MqttCallback; diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/MessageLog.java b/app/src/main/java/com/bonait/bnframework/common/helper/MessageLog.java deleted file mode 100644 index 8a11fdbb..00000000 --- a/app/src/main/java/com/bonait/bnframework/common/helper/MessageLog.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.bonait.bnframework.common.helper; - -import com.bonait.bnframework.common.db.res.AlertLogEnum; -import com.bonait.bnframework.common.db.res.UserLogEnum; -import com.bonait.bnframework.common.helper.I.IMessageLogNotify; -import com.bonait.bnframework.common.helper.I.IRun; - -import java.text.SimpleDateFormat; -import java.util.Date; - -public class MessageLog { - public static IMessageLogNotify MsgNotify; - - /** - * 日志触发通知 - */ - public static IRun AddNotify; - - public static String MsgInfo = ""; - - public static void ShowInfo(String msg) { - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date date = new Date(); - String tempMsg = formatter.format(date) + ":" + msg; - if(MsgInfo.length()>=8000)MsgInfo=""; - MsgInfo = tempMsg + "\r\n" + MsgInfo; - if (MsgNotify != null) - MsgNotify.InfoMsg(tempMsg); - if (AddNotify != null) AddNotify.Run(); - } - - public static void ShowWarning(String msg) { - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date date = new Date(); - String tempMsg = formatter.format(date) + ":" + msg; - if(MsgInfo.length()>=8000)MsgInfo=""; - MsgInfo = tempMsg + "\r\n" + MsgInfo; - if (MsgNotify != null) - MsgNotify.WarnMsg(tempMsg); - if (AddNotify != null) AddNotify.Run(); - } - - public static void ShowError(String msg) { - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date date = new Date(); - String tempMsg = formatter.format(date) + ":" + msg; - if(MsgInfo.length()>=8000)MsgInfo=""; - MsgInfo = tempMsg + "\r\n" + MsgInfo; - if (MsgNotify != null) - MsgNotify.ErrorMsg(tempMsg); - if (AddNotify != null) AddNotify.Run(); - } - - /** - * 用户操作日志 - * @param type - * @param msg - */ - public static void ShowUserMessage(UserLogEnum type, String msg) - { - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date date = new Date(); - String tempMsg = formatter.format(date) + ":" + msg; - if(MsgInfo.length()>=8000)MsgInfo=""; - MsgInfo = tempMsg + "\r\n" + MsgInfo; - if (MsgNotify != null) - MsgNotify.UserMsg(type,tempMsg); - if (AddNotify != null) AddNotify.Run(); - } - - /** - * 预警日志 - * @param type - * @param msg - */ - public static void ShowAlertMessage(AlertLogEnum type, String msg) - { - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date date = new Date(); - String tempMsg = formatter.format(date) + ":" + msg; - if(MsgInfo.length()>=8000)MsgInfo=""; - MsgInfo = tempMsg + "\r\n" + MsgInfo; - if (MsgNotify != null) - MsgNotify.AlertMsg(type,tempMsg); - if (AddNotify != null) AddNotify.Run(); - } - - -} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/ThreadManager.java b/app/src/main/java/com/bonait/bnframework/common/helper/ThreadManager.java deleted file mode 100644 index 6cac99af..00000000 --- a/app/src/main/java/com/bonait/bnframework/common/helper/ThreadManager.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.bonait.bnframework.common.helper; - -import com.bonait.bnframework.common.helper.I.IThread; -import com.bonait.bnframework.common.helper.mode.ThreadModel; -import java.util.concurrent.ConcurrentHashMap; - -public class ThreadManager { - private static volatile ThreadManager _Instance; - - public static ThreadManager Get() { - if (_Instance == null) - _Instance = new ThreadManager(); - return _Instance; - } - - private ThreadManager() { - - } - - public long RestartInterval = 2000; - ConcurrentHashMap ts = new ConcurrentHashMap<>(); - - private void Sleep(long millis) { - try { - Thread.sleep(millis); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - - public void StartLong(String Key, boolean IsRestart, IThread _thread) { - if (!ts.containsKey(Key)) { - ts.put(Key, new ThreadModel()); - ts.get(Key).RunThread = _thread; - ts.get(Key).ThreadObj = new Thread(() -> { - MessageLog.ShowInfo("启动线程:" + Key); - while (!ts.get(Key).IsCancel) { - if (IsRestart) { - try { - ts.get(Key).RunThread.Run(); - } catch (Exception ex) { - MessageLog.ShowError("多线程:" + Key + "运行发生异常,已重启,errorMsg:" + ex.toString()); - Sleep(RestartInterval); - } - } else { - try { - ts.get(Key).RunThread.Run(); - } catch (InterruptedException e) { - MessageLog.ShowError("多线程:" + Key + "运行发生异常,已退出,errorMsg:" + e.toString()); - } - } - } - try { - ts.get(Key).RunThread.RunComplete(); - MessageLog.ShowInfo("线程:[" + Key + "]--执行完成"); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - ts.remove(Key); - }); - ts.get(Key).ThreadObj.setName(Key); - ts.get(Key).ThreadObj.start(); - } else { - MessageLog.ShowWarning("任务-[" + Key + "]-已存在"); - } - } - - - public void Stop(String Key) { - if (ts.containsKey(Key)) { - ts.get(Key).IsCancel = true; - } - } - -} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/mode/ThreadModel.java b/app/src/main/java/com/bonait/bnframework/common/helper/mode/ThreadModel.java deleted file mode 100644 index 2f9fcfe7..00000000 --- a/app/src/main/java/com/bonait/bnframework/common/helper/mode/ThreadModel.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.bonait.bnframework.common.helper.mode; - -import com.bonait.bnframework.common.helper.I.IThread; - -public class ThreadModel { - public IThread RunThread; - public boolean IsCancel; - public Thread ThreadObj; -} diff --git a/app/src/main/java/com/bonait/bnframework/common/http/callback/json/JsonCallback.java b/app/src/main/java/com/bonait/bnframework/common/http/callback/json/JsonCallback.java index 69631f2b..bf40b690 100644 --- a/app/src/main/java/com/bonait/bnframework/common/http/callback/json/JsonCallback.java +++ b/app/src/main/java/com/bonait/bnframework/common/http/callback/json/JsonCallback.java @@ -8,7 +8,7 @@ import com.bonait.bnframework.common.constant.SPConstants; import com.bonait.bnframework.common.http.exception.TokenException; import com.bonait.bnframework.common.utils.PreferenceUtils; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.welcome.activity.WelcomeActivity; +import com.bonait.bnframework.ViewModel.ActivityViewModel.WelcomeActivity; import com.lzy.okgo.callback.AbsCallback; import com.lzy.okgo.exception.HttpException; import com.lzy.okgo.exception.StorageException; @@ -99,7 +99,7 @@ public abstract class JsonCallback extends AbsCallback { //删除本地过期的token PreferenceUtils.remove(SPConstants.TOKEN); PreferenceUtils.remove(SPConstants.USER_ID); - Intent intent = new Intent("com.bonait.bnframework.modules.welcome.activity.LoginActivity.ACTION_START"); + Intent intent = new Intent("com.bonait.bnframework.ViewModel.ActivityViewModel.LoginActivity.ACTION_START"); // 获取当前Activity(栈中最后一个压入的) Activity activity = ActivityLifecycleManager.get().currentActivity(); diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpHelper.java b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpHelper.java deleted file mode 100644 index 47e0bea5..00000000 --- a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpHelper.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.bonait.bnframework.common.modbus; - -import com.licheedev.modbus4android.ModbusWorker; -import com.serotonin.modbus4j.ModbusMaster; - - -public class ModbusTcpHelper extends ModbusWorker { - private static volatile ModbusTcpHelper instance = null; - - public static ModbusTcpHelper get() { - ModbusTcpHelper manager = instance; - if (manager == null) { - synchronized (ModbusTcpHelper.class) { - manager = instance; - if (manager == null) { - manager = new ModbusTcpHelper(); - instance = manager; - } - } - } - return manager; - } - - private ModbusTcpHelper() { - } - - /** - * 释放整个ModbusManager,单例会被置null - */ - public synchronized void release() { - super.release(); - instance = null; - } - - /** - * 获取 - * @return - */ - public synchronized ModbusMaster getModbusMaster() - { - return super.getModbusMaster(); - } - -} diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpServer.java b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpServer.java deleted file mode 100644 index 758545ec..00000000 --- a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpServer.java +++ /dev/null @@ -1,771 +0,0 @@ -package com.bonait.bnframework.common.modbus; - - -import android.os.Looper; - -import com.bonait.bnframework.MainApplication; -import com.bonait.bnframework.business.ConfigData; -import com.bonait.bnframework.common.constant.ConfigName; -import com.bonait.bnframework.common.constant.DataBus; -import com.bonait.bnframework.common.helper.DataFormat; -import com.bonait.bnframework.common.helper.I.IReadCallBack; -import com.bonait.bnframework.common.helper.I.IWriteCallBack; -import com.bonait.bnframework.common.helper.MessageLog; -import com.bonait.bnframework.common.utils.ToastUtils; -import com.licheedev.modbus4android.ModbusCallback; -import com.licheedev.modbus4android.ModbusParam; -import com.licheedev.modbus4android.ModbusRespException; -import com.licheedev.modbus4android.param.TcpParam; -import com.serotonin.modbus4j.ModbusMaster; -import com.serotonin.modbus4j.exception.ModbusInitException; -import com.serotonin.modbus4j.exception.ModbusTransportException; -import com.serotonin.modbus4j.msg.ReadCoilsResponse; -import com.serotonin.modbus4j.msg.ReadHoldingRegistersResponse; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.LineNumberReader; -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - - -public class ModbusTcpServer { - private static volatile ModbusTcpServer instance = null; - - public static ModbusTcpServer get() { - ModbusTcpServer manager = instance; - if (manager == null) { - synchronized (ModbusTcpServer.class) { - manager = instance; - if (manager == null) { - manager = new ModbusTcpServer(); - instance = manager; - } - } - } - return manager; - } - - private ModbusTcpServer() { - } - - static ModbusParam param; - - private int GetAddress(String address) { - if (address == null) return -1; - if (address.length() > 0) { - address = address.trim(); - if (address.toUpperCase().contains("M") && address.length() >= 4) { - String[] res = address.substring(1).split("[.]"); - if (res != null && res.length == 2) { - try { - int firstAdd = Integer.parseInt(res[0]); - int endAdd = Integer.parseInt(res[1]); - if (endAdd >= 0 && endAdd <= 7) { - return (firstAdd * 8) + 320 + endAdd; - } - } catch (NumberFormatException e) { - return -1; - } - } - } else if (address.toUpperCase().contains("I") && address.length() >= 4) { - String[] res = address.substring(1).split("[.]"); - if (res != null && res.length == 2) { - try { - int firstAdd = Integer.parseInt(res[0]); - int endAdd = Integer.parseInt(res[1]); - if (endAdd >= 0 && endAdd <= 7) { - return (firstAdd * 8) + endAdd; - } - } catch (NumberFormatException e) { - return -1; - } - } - } else if ((address.toUpperCase().contains("VW") || address.toUpperCase().contains("VD")) && address.length() >= 3) { - String res = address.substring(2); - if (res != null) { - try { - int tempAdd = Integer.parseInt(res); - return (tempAdd / 2) + 100; - } catch (NumberFormatException e) { - return -1; - } - } - } else { - try { - return Integer.parseInt(address); - } catch (NumberFormatException e) { - return -1; - } - } - } - return -1; - } - - /** - * 获取布尔位地址信息 - * 列:M2.5 = getBitSingleAdd("M",2,5); - * - * @param Prefix 地址标头 - * @param startAdd 起始地址编号 - * @param num 要获取的第几位数量 - * @return - */ - public String getBitSingleAdd(String Prefix, int startAdd, int num) { - if (num > 0) { - int FirstAdd = num / 8; - int EndAdd = num % 8; - if (EndAdd == 0) { - FirstAdd--; - EndAdd = 7; - } else { - EndAdd--; - } - return Prefix + FirstAdd + startAdd + "." + EndAdd; - } - return ""; - } - - /** - * Ping PLC地址是否通畅 - * @param address - * @param pingTimes ping的次数 - * @param timeOut 超时时间 10 - * @return - */ - public static boolean ping2(String address, int pingTimes, int timeOut) { - Process process = null; - try { - process = Runtime.getRuntime().exec( "ping " + "-c " + pingTimes + " -w " + timeOut+ " "+address); - InputStreamReader r = new InputStreamReader(process.getInputStream()); - - LineNumberReader returnData = new LineNumberReader(r); - - String returnMsg=""; - - String line = ""; - - while ((line = returnData.readLine()) != null) { - - System.out.println(line); - - returnMsg += line; - - } - - if(returnMsg.indexOf("100% packet loss")!=-1){ - System.out.println("与 " +address +" 连接不畅通."); - //ToastUtils.info("与 " +address +" 连接不畅通."); - return false; - } else{ - System.out.println("与 " +address +" 连接畅通."); - //ToastUtils.info("与 " +address +" 连接不畅通."); - return true; - } - } catch (IOException e) { - // e.printStackTrace(); - } - return false; - - } - - - /** - * 连接 - */ - public void Connect() throws InterruptedException { - boolean status = false; - while (!status) { - try { - //status为0则代表通,为1则代表不通。 - status =ping2(ConfigName.getInstance().Address,1,1); - Thread.sleep(1000); - } catch (InterruptedException e) { - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " 网络验证失败"); - } catch (Exception e) { - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " 网络验证失败"); - } - } - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " PLC通讯正常,准备连接!"); - - while (ConfigName.getInstance().PlcIsConnect==false) - { - ConnectPLC(); - Thread.sleep(5000); - } - } - - /** - * 连接PLC - */ - public static void ConnectPLC() - { - String host=ConfigName.getInstance().Address; - int port=ConfigName.getInstance().Post; - param = TcpParam.create(host, port) - .setTimeout(1000) - .setRetries(0) - .setEncapsulated(false) - .setKeepAlive(true); - ModbusTcpHelper.get().init(param, new ModbusCallback() { - @Override - public void onSuccess(ModbusMaster modbusMaster) { - ToastUtils.info("设备 " + ConfigName.getInstance().Address + " 连接成功"); - - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " 连接成功"); - ConfigName.getInstance().PlcIsConnect = true; - ConfigData.getInstance().PLC_Init(); - } - - @Override - public void onFailure(Throwable tr) { - ConfigName.getInstance().PlcIsConnect = false; - ToastUtils.info("设备 " + ConfigName.getInstance().Address + " 连接失败:" + tr.getMessage()); - MessageLog.ShowError("设备 " + ConfigName.getInstance().Address + " 连接失败:" + tr.getMessage()); - } - @Override - public void onFinally() { - - } - }); - } - -// /** -// * 重新连接Modbus -// */ -// public void ReconnectModbus() -// { -// try { -// -// ThreadManager.Get().StartLong("PLC断线重连线程", true, new IThread() { -// @Override -// public void Run() throws InterruptedException { -// try { -// boolean status =ping2(ConfigName.getInstance().Address,1,1); -// if(status) -// { -// ModbusMaster master= ModbusTcpHelper.get().getModbusMaster(); -// if (master==null || master.isConnected() == false) { -// ConnectPLC(); -// } -// Thread.sleep(20000); -// } -// } catch (Exception e) { -// Log.i("PLC", "PLC重连接失败!"+e.getMessage()); -// } -// } -// @Override -// public void RunComplete() throws InterruptedException { -// } -// }); -// }catch (Exception e) { -// MessageLog.ShowInfo("重新连接Modbus异常," +e.getMessage()); -// } -// } - - private Float BytesToFloat(byte[] buffers, DataFormat df) { - if (buffers.length == 4) { - byte[] bytes = new byte[4]; - if (df == DataFormat.ABCD) { - bytes[0] = buffers[3]; - bytes[1] = buffers[2]; - bytes[2] = buffers[1]; - bytes[3] = buffers[0]; - } else if (df == DataFormat.CDAB) { - bytes[0] = buffers[1]; - bytes[1] = buffers[0]; - bytes[2] = buffers[3]; - bytes[3] = buffers[2]; - } else if (df == DataFormat.BADC) { - bytes[0] = buffers[2]; - bytes[1] = buffers[3]; - bytes[2] = buffers[0]; - bytes[3] = buffers[1]; - } else if (df == DataFormat.DCBA) { - bytes[0] = buffers[0]; - bytes[1] = buffers[1]; - bytes[2] = buffers[2]; - bytes[3] = buffers[3]; - } - return ByteBuffer.wrap(bytes).getFloat(); - } - return 0.0f; - } - - private Integer BytesToInt(byte[] buffers, DataFormat df) { - if (buffers.length == 4) { - byte[] bytes = new byte[4]; - if (df == DataFormat.ABCD) { - bytes[0] = buffers[3]; - bytes[1] = buffers[2]; - bytes[2] = buffers[1]; - bytes[3] = buffers[0]; - } else if (df == DataFormat.CDAB) { - bytes[0] = buffers[1]; - bytes[1] = buffers[0]; - bytes[2] = buffers[3]; - bytes[3] = buffers[2]; - } else if (df == DataFormat.BADC) { - bytes[0] = buffers[2]; - bytes[1] = buffers[3]; - bytes[2] = buffers[0]; - bytes[3] = buffers[1]; - } else if (df == DataFormat.DCBA) { - bytes[0] = buffers[0]; - bytes[1] = buffers[1]; - bytes[2] = buffers[2]; - bytes[3] = buffers[3]; - } - return ByteBuffer.wrap(bytes).getInt(); - } - return 0; - } - - private byte[] IntToByte(int number) { - int temp = number; - byte[] b = new byte[4]; - for (int i = 0; i < b.length; i++) { - b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位 - temp = temp >> 8; // 向右移8位 - } - return b; - } - - private short[] IntToShorts(int value) { - short[] res = new short[2]; - int temp = value; - byte[] b = new byte[4]; - for (int i = 0; i < b.length; i++) { - b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位 - temp = temp >> 8; // 向右移8位 - } - for (int i = 0; i < res.length; i++) { - short s0 = (short) (b[i * 2] & 0xff);// 最低位 - short s1 = (short) (b[i * 2 + 1] & 0xff); - s1 <<= 8; - res[i] = (short) (s0 | s1); - } - return res; - } - - public static String GetString(short[] src, int start, int len) throws UnsupportedEncodingException { - short[] temp = new short[len]; - for (int i = 0; i < len; i++) { - temp[i] = src[i + start]; - } - byte[] bytesTemp = shorts2Bytes(temp); - for (int i = 0; i < bytesTemp.length; i++) { - byte b = bytesTemp[i]; - } - String str = new String(bytesTemp, "UTF-8"); - return str; - } - - public static byte[] shorts2Bytes(short[] data) { - byte[] byteValue = new byte[data.length * 2]; - for (int i = 0; i < data.length; i++) { - byteValue[i * 2] = (byte) (data[i] & 0xff); - byteValue[i * 2 + 1] = (byte) ((data[i] & 0xff00) >> 8); - } - return byteValue; - } - - /*** - *读取实时状态 - * @param Address the address - * @param length 读取的长度 3 - * @param callback 读取成功的回调 - */ - public void ReadStatus(String Address, int length, IReadCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - try { - ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length); - byte[] data = res.getData(); - byte[] tempData = new byte[6]; - tempData[0] = data[1]; - tempData[1] = data[0]; - if (callback != null) callback.onSuccess(tempData); - } catch (InterruptedException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - /*** - *读取扫码数据 - * @param Address the address - * @param length 读取的长度 - * @param callback 读取成功的回调 - */ - public void ReadString(String Address, int length, IReadCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - try { - ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length); - byte[] data = res.getData(); - byte[] data1 = Arrays.copyOfRange(data, 0, 18); - //36 GUID 18 Number - String id = ""; - try { - byte[] tempdata = new byte[18]; - for (int i = 0; i < data1.length; i++) { - if (i % 2 == 0) { - - tempdata[i + 1] = data1[i]; - } else { - tempdata[i - 1] = data1[i]; - } - } - id = new String(tempdata, "UTF-8").trim(); - } catch (UnsupportedEncodingException ex) { - } - if (callback != null) callback.onSuccess(id); - } catch (InterruptedException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - public void WriteString(String Address, int length, IWriteCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - short[] send = new short[length]; - for (short item : send) { - item = 0; - } - try { - ModbusTcpHelper.get().syncWriteRegisters(1, add, send); - if (callback != null) - callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - public void ReadShort(String Address, int length, IReadCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - try { - ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length); - short[] data = res.getShortData(); - if (data.length == length) { - if (callback != null) callback.onSuccess(data); - } - } catch (InterruptedException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - public void ReadBool(String Address, int length, IReadCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - try { - ReadCoilsResponse res = ModbusTcpHelper.get().syncReadCoil(1, add, length); - boolean[] data = res.getBooleanData(); - boolean[] result = Arrays.copyOfRange(data, 0, length); - if (result.length == length) { - if (callback != null) callback.onSuccess(result); - } - } catch (InterruptedException e) { - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - public void ReadFloat(String Address, int length, IReadCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - try { - ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length); - byte[] data = res.getData(); - float[] tempValues = new float[length]; - for (int i = 0; i < length; i++) { - byte[] tempData = new byte[4]; - for (int m = 0; m < 4; m++) { - tempData[m] = data[i * 4 + m]; - } - tempValues[i] = BytesToFloat(tempData, DataFormat.ABCD); - } - if (tempValues.length == length) { - if (callback != null) callback.onSuccess(tempValues); - } - } catch (InterruptedException e) { - MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - public void ReadInt(String Address, int length, IReadCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - try { - ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(1, add, length * 2); - byte[] data = res.getData(); - int[] tempValues = new int[length]; - if(data.length>=4) - { - for (int i = 0; i < length; i++) { - byte[] tempData = new byte[4]; - for (int m = 0; m < 4; m++) { - tempData[m] = data[i * 4 + m]; - } -// Integer a1 = tempValues[i] = BytesToInt(tempData, DataFormat.ABCD); -// Integer a2 = tempValues[i] = BytesToInt(tempData, DataFormat.BADC); -// Integer a3 = tempValues[i] = BytesToInt(tempData, DataFormat.CDAB); -// Integer a4 = tempValues[i] = BytesToInt(tempData, DataFormat.DCBA); - tempValues[i] = BytesToInt(tempData, DataFormat.BADC); - } - }else - { - MessageLog.ShowError("ReadInt onFailure,Address=" ); - - } - if (callback != null) callback.onSuccess(tempValues); - } catch (InterruptedException e) { - MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - public void WriteShort(String Address, short Value, IWriteCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - short[] send = new short[1]; - send[0] = Value; - try { - ModbusTcpHelper.get().syncWriteRegisters(1, add, send); - if (callback != null) - callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - public void WriteBool(String Address, boolean Value, IWriteCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - try { - ModbusTcpHelper.get().syncWriteCoil(1, add, Value); - if (callback != null) - callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - public void WriteFloat(String Address, float Value, IWriteCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - int intBits = Float.floatToRawIntBits(Value); - short[] send = new short[]{(short) ((intBits >> 16) & 0xffff), (short) (intBits & 0xffff)}; - try { - ModbusTcpHelper.get().syncWriteRegisters(1, add, send); - - if (callback != null) callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - public void WriteInt(String Address, int Value, IWriteCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - short[] send = IntToShorts(Value); - try { - ModbusTcpHelper.get().syncWriteRegisters(1, add, send); - if (callback != null) callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - public void WriteShort(String Address, short Value) { - int add = GetAddress(Address); - if (add < 0) return; - short[] send = new short[1]; - send[0] = Value; - try { - ModbusTcpHelper.get().syncWriteRegisters(1, add, send); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } - } - - public void WriteBool(String Address, boolean Value) { - int add = GetAddress(Address); - if (add < 0) return; - - try { - ModbusTcpHelper.get().syncWriteCoil(1, add, Value); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } - } - - public void WriteFloat(String Address, float Value) { - int add = GetAddress(Address); - if (add < 0) return; - int intBits = Float.floatToRawIntBits(Value); - short[] send = new short[]{(short) ((intBits >> 16) & 0xffff), (short) (intBits & 0xffff)}; - try { - ModbusTcpHelper.get().syncWriteRegisters(1, add, send); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } - } - - public void WriteInt(String Address, int Value) { - int add = GetAddress(Address); - if (add < 0) return; - short[] send = IntToShorts(Value); - try { - ModbusTcpHelper.get().syncWriteRegisters(1, add, send); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } - } - -} diff --git a/app/src/main/java/com/bonait/bnframework/common/oss/OssHelper.java b/app/src/main/java/com/bonait/bnframework/common/oss/OssHelper.java index 93c80c2d..cf05fe29 100644 --- a/app/src/main/java/com/bonait/bnframework/common/oss/OssHelper.java +++ b/app/src/main/java/com/bonait/bnframework/common/oss/OssHelper.java @@ -17,10 +17,9 @@ import com.alibaba.sdk.android.oss.common.auth.OSSPlainTextAKSKCredentialProvide import com.alibaba.sdk.android.oss.internal.OSSAsyncTask; import com.alibaba.sdk.android.oss.model.PutObjectRequest; import com.alibaba.sdk.android.oss.model.PutObjectResult; +import com.bonait.bnframework.HBL.Interface.IRunT; import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.common.constant.ConfigName; -import com.bonait.bnframework.common.helper.I.IRun; -import com.bonait.bnframework.common.helper.I.IRunT; import com.bonait.bnframework.common.image.utils.LocalCacheUtils; import com.bonait.bnframework.common.model.ResAPI; diff --git a/app/src/main/java/com/bonait/bnframework/common/utils/UpdateAppUtils.java b/app/src/main/java/com/bonait/bnframework/common/utils/UpdateAppUtils.java index 81c66a72..c14b48ee 100644 --- a/app/src/main/java/com/bonait/bnframework/common/utils/UpdateAppUtils.java +++ b/app/src/main/java/com/bonait/bnframework/common/utils/UpdateAppUtils.java @@ -4,23 +4,16 @@ import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Build; -import android.os.Message; import androidx.core.content.FileProvider; import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.common.constant.ConfigName; -import com.bonait.bnframework.common.constant.Constants; -import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.helper.Json; import com.bonait.bnframework.common.helper.mode.ResVersion; import com.bonait.bnframework.common.helper.mode.VersionMode; -import com.bonait.bnframework.common.helper.mode.VersionResponse; import com.bonait.bnframework.common.http.callback.files.FileProgressDialogCallBack; import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback; -import com.bonait.bnframework.common.message.MessageLooper; -import com.bonait.bnframework.common.message.MessageManager; -import com.bonait.bnframework.modules.mine.model.UpdateAppPo; import com.lzy.okgo.OkGo; import com.lzy.okgo.model.Response; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; diff --git a/app/src/main/java/com/bonait/bnframework/test/TestActivity.java b/app/src/main/java/com/bonait/bnframework/test/TestActivity.java index 9a6ec578..44ea76be 100644 --- a/app/src/main/java/com/bonait/bnframework/test/TestActivity.java +++ b/app/src/main/java/com/bonait/bnframework/test/TestActivity.java @@ -16,8 +16,8 @@ import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback; import com.bonait.bnframework.common.model.mode.BaseCodeJson; import com.bonait.bnframework.common.utils.AppUtils; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.welcome.model.AppLoginPo; -import com.bonait.bnframework.modules.mine.model.UpdateAppPo; +import com.bonait.bnframework.Model.AppLoginPo; +import com.bonait.bnframework.Model.UpdateAppPo; import com.lzy.okgo.OkGo; import com.lzy.okgo.model.Response; import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton; diff --git a/app/src/main/res/drawable/bg_btn_cancel.xml b/app/src/main/res/drawable/bg_btn_cancel.xml new file mode 100644 index 00000000..09e6b2b2 --- /dev/null +++ b/app/src/main/res/drawable/bg_btn_cancel.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_btn_dialog_qupenren.xml b/app/src/main/res/drawable/bg_btn_dialog_qupenren.xml new file mode 100644 index 00000000..8b29f758 --- /dev/null +++ b/app/src/main/res/drawable/bg_btn_dialog_qupenren.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dialog_back.xml b/app/src/main/res/drawable/dialog_back.xml new file mode 100644 index 00000000..13592de1 --- /dev/null +++ b/app/src/main/res/drawable/dialog_back.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dialog_error_title_back.xml b/app/src/main/res/drawable/dialog_error_title_back.xml new file mode 100644 index 00000000..ba3f2fb2 --- /dev/null +++ b/app/src/main/res/drawable/dialog_error_title_back.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dialog_info_title_back.xml b/app/src/main/res/drawable/dialog_info_title_back.xml new file mode 100644 index 00000000..26ae15d9 --- /dev/null +++ b/app/src/main/res/drawable/dialog_info_title_back.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dialog_warn_title_back.xml b/app/src/main/res/drawable/dialog_warn_title_back.xml new file mode 100644 index 00000000..2e8fa22c --- /dev/null +++ b/app/src/main/res/drawable/dialog_warn_title_back.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_bottom_navigation2.xml b/app/src/main/res/layout/activity_bottom_navigation2.xml index b8e92066..e681a081 100644 --- a/app/src/main/res/layout/activity_bottom_navigation2.xml +++ b/app/src/main/res/layout/activity_bottom_navigation2.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="?attr/app_primary_color" - tools:context=".modules.home.activity.BottomNavigation2Activity"> + tools:context=".ViewModel.ActivityViewModel.BottomNavigation2Activity"> + tools:context=".ViewModel.ActivityViewModel.BottomNavigationNewActivity"> - - + + tools:context=".ViewModel.ActivityViewModel.BunkerSetupActivity"> - - - - - - + diff --git a/app/src/main/res/layout/activity_cooking.xml b/app/src/main/res/layout/activity_cooking.xml index 511e1a86..0b8c4560 100644 --- a/app/src/main/res/layout/activity_cooking.xml +++ b/app/src/main/res/layout/activity_cooking.xml @@ -7,7 +7,7 @@ android:background="@color/red_primary" android:fitsSystemWindows="true" android:orientation="vertical" - tools:context=".modules.home.fragment.from.CookingActivity"> + tools:context=".ViewModel.ActivityViewModel.CookingActivity"> - - @@ -99,7 +99,7 @@ android:textSize="14dp" /> - - - - - - - - - - - - + tools:context=".ViewModel.ActivityViewModel.CookingSimulatedActivity"> - @@ -121,7 +121,7 @@ android:layout_marginTop="0dp" android:orientation="vertical"> - - - - - - - - - - - + tools:context=".ViewModel.ActivityViewModel.CpActivity"> diff --git a/app/src/main/res/layout/activity_dialog.xml b/app/src/main/res/layout/activity_dialog.xml new file mode 100644 index 00000000..2481c0d8 --- /dev/null +++ b/app/src/main/res/layout/activity_dialog.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + +