diff --git a/app/build.gradle b/app/build.gradle index 345583d..8a409bb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,12 +51,13 @@ dependencies { implementation 'com.google.android.material:material:1.5.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.recyclerview:recyclerview:1.2.1' + implementation 'com.google.android.libraries.places:places:2.5.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' implementation 'com.qmuiteam:qmui:2.0.0-alpha10' //腾讯ui包 implementation("com.iqiyi.xcrash:xcrash-android-lib:3.1.0") //爱奇艺捕获异常插件 - implementation files('libs\\gson-2.2.2.jar') +// implementation files('libs\\gson-2.2.2.jar') implementation files('libs\\sdkapi.jar') compileOnly files('libs/sdkapi.jar') implementation files('libs/modbus4Android-1.2.jar') diff --git a/app/src/main/java/com/example/bpa/LoginActivity.java b/app/src/main/java/com/example/bpa/LoginActivity.java index 9f5ead4..611f1c8 100644 --- a/app/src/main/java/com/example/bpa/LoginActivity.java +++ b/app/src/main/java/com/example/bpa/LoginActivity.java @@ -10,6 +10,7 @@ import com.example.bpa.app.Main; import com.example.bpa.config.ConfigName; import com.example.bpa.db.QueryDB; import com.example.bpa.db.mode.BPA_USER; +import com.example.bpa.helper.MessageLog; import com.example.bpa.helper.T; public class LoginActivity extends Activity implements View.OnClickListener { @@ -60,6 +61,7 @@ public class LoginActivity extends Activity implements View.OnClickListener { if (user!=null) { ConfigName.getInstance().user = user; Main.getInstance().SavePZ();//保存配置 + MessageLog.ShowInfo("登录"); T.show(LoginActivity.this, "登录成功!"); try { Intent intent = new Intent(LoginActivity.this, MainActivity.class); diff --git a/app/src/main/java/com/example/bpa/Model/IMessageLogNotify.java b/app/src/main/java/com/example/bpa/Model/IMessageLogNotify.java index 32baa89..fbebc08 100644 --- a/app/src/main/java/com/example/bpa/Model/IMessageLogNotify.java +++ b/app/src/main/java/com/example/bpa/Model/IMessageLogNotify.java @@ -3,7 +3,7 @@ package com.example.bpa.Model; public interface IMessageLogNotify { void ErrorMsg(String msg); - void InfoMsg(String msg); + void InfoMsg(String msg,String datetiem); void WarnMsg(String msg); } diff --git a/app/src/main/java/com/example/bpa/app/DeviceData.java b/app/src/main/java/com/example/bpa/app/DeviceData.java index dc34e4b..1f62a41 100644 --- a/app/src/main/java/com/example/bpa/app/DeviceData.java +++ b/app/src/main/java/com/example/bpa/app/DeviceData.java @@ -4,6 +4,7 @@ import com.example.bpa.Model.IReadCallBack; import com.example.bpa.Model.IRun; import com.example.bpa.Model.IThread; import com.example.bpa.Model.IWriteCallBack; +import com.example.bpa.helper.MessageLog; import com.example.bpa.helper.RTrig; import com.example.bpa.helper.ThreadManager; @@ -17,6 +18,7 @@ public class DeviceData { if (_instance == null) _instance = new DeviceData(); return _instance; + } public void Init() { diff --git a/app/src/main/java/com/example/bpa/db/QueryDB.java b/app/src/main/java/com/example/bpa/db/QueryDB.java index e930d48..c104598 100644 --- a/app/src/main/java/com/example/bpa/db/QueryDB.java +++ b/app/src/main/java/com/example/bpa/db/QueryDB.java @@ -1,10 +1,7 @@ package com.example.bpa.db; - import android.content.ContentValues; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; -import android.util.Log; - import com.example.bpa.config.ConfigName; import com.example.bpa.db.file.DBHelper; import com.example.bpa.db.mode.BPA_ALERTLOG; @@ -26,7 +23,6 @@ import com.example.bpa.db.mode.ModeBase; import com.example.bpa.helper.Tools; import com.example.bpa.view.mode.ResGoodsRecipe; import com.example.bpa.view.mode.ResSilosMode; - import java.lang.reflect.Field; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -95,6 +91,39 @@ public class QueryDB { return Delete(BPA_MATERIAL.class, data.id); } +// public static boolean DeleteMaterial(String id){ +// boolean result = false; +// SQLiteDatabase db = helper.getWritableDatabase(); +// try { +// db.beginTransaction(); +// StringBuilder sql = new StringBuilder(); +// sql.append("delete from ").append(BPA_MATERIAL.class.getSimpleName()).append(" where id=?"); +// db.execSQL(sql.toString(), new String[]{id}); +// db.setTransactionSuccessful(); +// result = true; +// }catch (SQLException e) { +// e.printStackTrace(); +// result = false; +// }finally { +// db.endTransaction(); +// } +// +// try { +// db.beginTransaction(); +// StringBuilder sql = new StringBuilder(); +// sql.append("delete from ").append(BPA_SILOSANDMATERIAL.class.getSimpleName()).append(" where materialID=?"); +// db.execSQL(sql.toString(), new String[]{id}); +// db.setTransactionSuccessful(); +// }catch (SQLException e) { +// e.printStackTrace(); +// +// }finally { +// db.endTransaction();//结束第二个事务,回滚或提交操作 +// } +// db.close(); +// return result; +// } + /** @@ -114,7 +143,7 @@ public class QueryDB { return data; } /** - * 根据id获取物料 + * 根据物料id获取物料 * * @param * @return @@ -363,7 +392,7 @@ public class QueryDB { } /** - * 根据料仓id查询物料 + * 根据料仓id查询物料id * @param id * @return */ @@ -416,6 +445,34 @@ public class QueryDB { } return data; } + + /** + * 根据料仓id查询物料 + * @param id + * @return + */ + public static List GetMaterialBySilosID(String id){ + List data = new ArrayList<>(); + List res = GetMaterialList(id);//根据料仓ID获取物料ID + if (res.size() == 0){ + return data; + } + if (res.get(0).equals("")){return data;} + //根据物料id查询物料 + String orderby=Desc_Time_Up;//先按排序 创建时间倒序 + String where="isDelete=? and id=?"; + + for (String s : res) { + String[] args=new String[] { "0",s }; + List obj=Get(BPA_MATERIAL.class,where,args,orderby); + for (Object o : obj) { + data.add((BPA_MATERIAL) o); + } + + } + return data; + + } //endregion //region BPA_GOODS 商品表 @@ -881,10 +938,12 @@ public class QueryDB { ArrayList obj = Get(BPA_LOG.class, where, args, orderby); for (Object k : obj) { data.add((BPA_LOG) k); + } return data; } + /** * 获取所有今日日志 * @@ -1307,6 +1366,7 @@ public class QueryDB { // cv.put(key, (Date) value); // } } + SQLiteDatabase db = helper.getWritableDatabase(); long insert = db.insert(c.getSimpleName(), null, cv); db.close(); diff --git a/app/src/main/java/com/example/bpa/helper/MessageLog.java b/app/src/main/java/com/example/bpa/helper/MessageLog.java index df6da1a..f2c9ade 100644 --- a/app/src/main/java/com/example/bpa/helper/MessageLog.java +++ b/app/src/main/java/com/example/bpa/helper/MessageLog.java @@ -12,7 +12,7 @@ public class MessageLog { SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); Date date = new Date(); if (MsgNotify != null) - MsgNotify.InfoMsg(formatter.format(date) + ":" + msg); + MsgNotify.InfoMsg(formatter.format(date) + ":" + msg,formatter.format(date)); } public static void ShowWarning(String msg) { diff --git a/app/src/main/java/com/example/bpa/helper/Tools.java b/app/src/main/java/com/example/bpa/helper/Tools.java index 67a2266..cf533c5 100644 --- a/app/src/main/java/com/example/bpa/helper/Tools.java +++ b/app/src/main/java/com/example/bpa/helper/Tools.java @@ -1,5 +1,4 @@ package com.example.bpa.helper; - import android.content.Context; import android.content.res.AssetManager; import android.graphics.Bitmap; @@ -14,12 +13,9 @@ import android.graphics.RectF; import android.os.Build; import android.os.Environment; import android.view.View; - import com.google.gson.Gson; - import org.json.JSONException; import org.json.JSONObject; - import java.io.IOException; import java.io.InputStream; import java.util.HashMap; diff --git a/app/src/main/java/com/example/bpa/view/fragment/SystemSetFragment.java b/app/src/main/java/com/example/bpa/view/fragment/SystemSetFragment.java index 9d345a4..bd32ba0 100644 --- a/app/src/main/java/com/example/bpa/view/fragment/SystemSetFragment.java +++ b/app/src/main/java/com/example/bpa/view/fragment/SystemSetFragment.java @@ -17,6 +17,9 @@ import android.widget.Button; import com.example.bpa.Model.IMessageLogNotify; import com.example.bpa.R; +import com.example.bpa.config.ConfigName; +import com.example.bpa.db.QueryDB; +import com.example.bpa.db.mode.BPA_LOG; import com.example.bpa.helper.MessageLog; import com.example.bpa.view.fragment.setting.Fragment_lcparameter; @@ -52,13 +55,19 @@ public class SystemSetFragment extends Fragment implements View.OnClickListener @Override public void ErrorMsg(String msg) { Log.e("Error", msg); + } @Override - public void InfoMsg(String msg) { + public void InfoMsg(String msg,String datetime) { + BPA_LOG log = new BPA_LOG(); + log.userID = ConfigName.getInstance().user.userID; + log.createTime = datetime; + log.type = 1; + log.text = msg; + QueryDB.Addlog(log); Log.i("Info", msg); } - @Override public void WarnMsg(String msg) { Log.w("Warn", msg); diff --git a/app/src/main/java/com/example/bpa/view/fragment/setting/Fragment_lcparameter.java b/app/src/main/java/com/example/bpa/view/fragment/setting/Fragment_lcparameter.java index d8cde3d..2b2389e 100644 --- a/app/src/main/java/com/example/bpa/view/fragment/setting/Fragment_lcparameter.java +++ b/app/src/main/java/com/example/bpa/view/fragment/setting/Fragment_lcparameter.java @@ -11,18 +11,44 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; +import android.widget.CompoundButton; +import android.widget.EditText; import android.widget.LinearLayout; +import android.widget.Switch; +import com.example.bpa.Model.IWriteCallBack; import com.example.bpa.R; +import com.example.bpa.app.DeviceData; +import com.example.bpa.helper.T; -public class Fragment_lcparameter extends Fragment { +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class Fragment_lcparameter extends Fragment implements CompoundButton.OnCheckedChangeListener { private View view; LinearLayout mylayout; + + //通道校准值 + + EditText passwayText_1,passwayText_2,passwayText_3,passwayText_4,passwayText_5,passwayText_6,passwayText_7,passwayText_8,passwayText_9,passwayText_10; + + EditText timeText; + List editTextLists = new ArrayList(); + //通道校准开关 + Switch Switch_1,Switch_2,Switch_3,Switch_4,Switch_5,Switch_6,Switch_7,Switch_8,Switch_9,Switch_10; + List switchLists = new ArrayList(); + Button StartButton; + + Button SaveButton; @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - view = inflater.inflate(R.layout.fragment_system_capabilities, container,false); + view = inflater.inflate(R.layout.fragment_lcparameter, container,false); Init(); + InitEvent(); + InitData(); return view; } @@ -30,5 +56,200 @@ public class Fragment_lcparameter extends Fragment { private void Init(){ mylayout = view.findViewById(R.id.lcparameter_layout); mylayout.setBackgroundColor(Color.TRANSPARENT); + //校准数值 + + passwayText_1 = view.findViewById(R.id.passwayText_1); + passwayText_2 = view.findViewById(R.id.passwayText_2); + passwayText_3 = view.findViewById(R.id.passwayText_3); + passwayText_4 = view.findViewById(R.id.passwayText_4); + passwayText_5 = view.findViewById(R.id.passwayText_5); + passwayText_6 = view.findViewById(R.id.passwayText_6); + passwayText_7 = view.findViewById(R.id.passwayText_7); + passwayText_8 = view.findViewById(R.id.passwayText_8); + passwayText_9 = view.findViewById(R.id.passwayText_9); + passwayText_10 = view.findViewById(R.id.passwayText_10); + editTextLists = Arrays.asList(passwayText_1,passwayText_2,passwayText_3,passwayText_4,passwayText_5,passwayText_6,passwayText_7,passwayText_8,passwayText_9,passwayText_10); + + //校准开关 + Switch_1 = view.findViewById(R.id.Switch_1); + Switch_2 = view.findViewById(R.id.Switch_2); + Switch_3 = view.findViewById(R.id.Switch_3); + Switch_4 = view.findViewById(R.id.Switch_4); + Switch_5 = view.findViewById(R.id.Switch_5); + Switch_6 = view.findViewById(R.id.Switch_6); + Switch_7 = view.findViewById(R.id.Switch_7); + Switch_8 = view.findViewById(R.id.Switch_8); + Switch_9 = view.findViewById(R.id.Switch_9); + Switch_10 = view.findViewById(R.id.Switch_10); + + //校准按钮 + StartButton = view.findViewById(R.id.StartButton); + + timeText = view.findViewById(R.id.edi_time); + SaveButton = view.findViewById(R.id.savetime); } + + //点击事件 + private void InitEvent(){ + Switch_1.setOnCheckedChangeListener(this); + Switch_2.setOnCheckedChangeListener(this); + Switch_3.setOnCheckedChangeListener(this); + Switch_4.setOnCheckedChangeListener(this); + Switch_5.setOnCheckedChangeListener(this); + Switch_6.setOnCheckedChangeListener(this); + Switch_7.setOnCheckedChangeListener(this); + Switch_8.setOnCheckedChangeListener(this); + Switch_9.setOnCheckedChangeListener(this); + Switch_10.setOnCheckedChangeListener(this); + + //开始校准 + StartButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + DeviceData.Get().setChStartCalibration(new IWriteCallBack() { + @Override + public void onSuccess() { + T.show(view.getContext(),"通道开始校准"); + } + + @Override + public void onFailure(String ErrorMsg) { + T.show(view.getContext(),"通道开始校准失败"); + } + }); + } + }); + + SaveButton.setOnClickListener(new View.OnClickListener(){ + @Override + public void onClick(View v) { + new Thread(new Runnable() { + @Override + public void run() { + try { + String stime = timeText.getText().toString(); + if(stime.equals("")){return;} + Float ftime = Float.parseFloat(stime); + DeviceData.Get().setCalibrationReferenceTime(ftime,new IWriteCallBack() { + @Override + public void onSuccess() { + T.show(view.getContext(),"校准时间写入成功"); + } + + @Override + public void onFailure(String ErrorMsg) { + T.show(view.getContext(),"校准时间写入失败"); + } + }); + }catch (ArithmeticException e) { + e.printStackTrace(); + } + } + }); + + + } + }); + + } + + //初始化数据 + private void InitData(){ + //初始化标准值数据 + for (int i = 0; i <10;i++){ + String s = String.valueOf(DeviceData.Get().getCalibrationValue(i+1)); + editTextLists.get(i).setText(s); + } + String time = String.valueOf(DeviceData.Get().getCalibrationReferenceTime()); + timeText.setText(time); + + + + } + + //switch 事件 + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + switch (buttonView.getId()){ + case R.id.Switch_1: + SwitchClick(1,isChecked); + break; + case R.id.Switch_2: + SwitchClick(2,isChecked); + break; + case R.id.Switch_3: + SwitchClick(3,isChecked); + break; + case R.id.Switch_4: + SwitchClick(4,isChecked); + break; + case R.id.Switch_5: + SwitchClick(5,isChecked); + break; + case R.id.Switch_6: + SwitchClick(6,isChecked); + break; + case R.id.Switch_7: + SwitchClick(7,isChecked); + break; + case R.id.Switch_8: + SwitchClick(8,isChecked); + break; + case R.id.Switch_9: + SwitchClick(9,isChecked); + break; + case R.id.Switch_10: + SwitchClick(10,isChecked); + break; + } + } + + private void SwitchClick(int index, boolean isChecked){ + StringBuffer sb = new StringBuffer("PLC写入:"); + new Thread (new Runnable() { + public void run() { + if (isChecked){ //校准开关开启状态才会写入值 + + + String value = editTextLists.get(index-1).getText().toString(); + DeviceData.Get().setCalibrationValue(Short.parseShort(value),index, new IWriteCallBack() { + @Override + public void onSuccess() { + sb.append("通道"); + sb.append(index); + sb.append("校准值写入成功;"); + } + + @Override + public void onFailure(String ErrorMsg) { + sb.append("通道"); + sb.append(index); + sb.append("校准值写入失败;"); + } + }); + } + DeviceData.Get().setChCalibrationSwitch(isChecked, index, new IWriteCallBack() { + @Override + public void onSuccess() { + sb.append("通道"); + sb.append(index); + sb.append("校准开关成功;"); + + } + + @Override + public void onFailure(String ErrorMsg) { + sb.append("通道"); + sb.append(index); + sb.append("校准开关失败;"); + + } + }); + } + }); + + + T.show(view.getContext(), sb.toString()); + } + } \ No newline at end of file diff --git a/app/src/main/java/com/example/bpa/view/from/lcsz_activity.java b/app/src/main/java/com/example/bpa/view/from/lcsz_activity.java index 541ab16..1ddaee8 100644 --- a/app/src/main/java/com/example/bpa/view/from/lcsz_activity.java +++ b/app/src/main/java/com/example/bpa/view/from/lcsz_activity.java @@ -48,8 +48,8 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList RecyclerView recyclerView; //物料listview ListView materiallist; - - + //materiallist父控件 + View material_parent; //物料列表 ArrayList bpa_materials=new ArrayList<>(); //当前选中的料仓id @@ -79,6 +79,7 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList //横向排列 recyclerView = this.findViewById(R.id.lc_view); materiallist = this.findViewById(R.id.materials); + material_parent =(View) materiallist.getParent(); try { //加载 recyclercview数据 MyLayoutManager layout = new MyLayoutManager(); @@ -91,18 +92,23 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList //加载materials数据 if(bpa_silos.size()>0){ for (BPA_SILOS silo : bpa_silos){ - String resmaterialid = QueryDB.GetMaterialList(silo.id).size()==0? "-1" : QueryDB.GetMaterialList(silo.id).get(0); - String material_name = "未设置"; - String material_id = ""; - if (resmaterialid != "-1"){ - BPA_MATERIAL res= QueryDB.GetMaterialbyid(resmaterialid); - if (res!=null) { - material_name = res.name; - material_id = res.id; - } - +// String resmaterialid = QueryDB.GetMaterialList(silo.id).size()==0? "-1" : QueryDB.GetMaterialList(silo.id).get(0); +// String material_name = "未设置"; +// String material_id = ""; +// if (resmaterialid != "-1"){ +// BPA_MATERIAL res= QueryDB.GetMaterialbyid(resmaterialid); +// if (res!=null) { +// material_name = res.name; +// material_id = res.id; +// } +// +// } + List m = QueryDB.GetMaterialBySilosID(silo.id); + if(m.size()>0) { + datas.add(new lcMode(silo.id, silo.num, m.get(0).name, "", m.get(0).id)); + }else { + datas.add(new lcMode(silo.id, silo.num, "未设置", "", "")); } - datas.add(new lcMode(silo.id,silo.num,material_name,"",material_id)); } } @@ -156,8 +162,7 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList public void onItemClick(AdapterView parent, View view, int position, long id) { ArrayAdapter viewHolder = (ArrayAdapter)materiallist.getAdapter(); if (viewHolder instanceof selectitem_adapter){ - View listViewParent = (View) materiallist.getParent(); - listViewParent.setVisibility(View.GONE); + material_parent.setVisibility(View.GONE);//隐藏父控件 if (currentSilo!=null){ BPA_SILOSANDMATERIAL item = new BPA_SILOSANDMATERIAL(); item.silosID = currentSilo.id; @@ -174,6 +179,14 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList } } }); + + //region materials父控件点击事件 + material_parent.setOnClickListener(new View.OnClickListener(){ + @Override + public void onClick(View v) { + material_parent.setVisibility(View.GONE);//隐藏materiallist + } + }); //endregion } diff --git a/app/src/main/java/com/example/bpa/view/from/zdqx_activity.java b/app/src/main/java/com/example/bpa/view/from/zdqx_activity.java index bdf3df4..818c6bf 100644 --- a/app/src/main/java/com/example/bpa/view/from/zdqx_activity.java +++ b/app/src/main/java/com/example/bpa/view/from/zdqx_activity.java @@ -1,13 +1,24 @@ package com.example.bpa.view.from; +import static com.example.bpa.helper.T.show; + import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; +import android.widget.Button; +import android.widget.CompoundButton; +import android.widget.EditText; import android.widget.ImageView; +import android.widget.ProgressBar; +import android.widget.Switch; import android.widget.TextView; +import com.example.bpa.Model.IWriteCallBack; import com.example.bpa.R; +import com.example.bpa.app.DeviceData; +import com.example.bpa.db.QueryDB; +import com.example.bpa.helper.T; /** * 自动清洗 @@ -22,6 +33,18 @@ public class zdqx_activity extends AppCompatActivity implements View.OnClickList * 标题设置 */ TextView gongneng_title; + //参数 + EditText edit_pstime,edit_jstime,edit_jqxjtime,edit_xhtime; + //按钮 + Button bt_save,bt_start; + //switch + Switch qsmode; + //进度条 + ProgressBar progress_bar; + +// TextView progress_text; + + boolean mValue = false; //endregion //region 私有函数 @@ -31,6 +54,8 @@ public class zdqx_activity extends AppCompatActivity implements View.OnClickList setContentView(R.layout.activity_zdqx); Init(); initEvents(); + InitData(); + startListening(); } //endregion @@ -42,11 +67,20 @@ public class zdqx_activity extends AppCompatActivity implements View.OnClickList private void Init(){ gongneng_fanhui = this.findViewById(R.id.gongneng_fanhui); gongneng_title = this.findViewById(R.id.gongneng_title); + edit_pstime = this.findViewById(R.id.edit_pstime); + edit_jstime = this.findViewById(R.id.edit_jstime); + edit_jqxjtime = this.findViewById(R.id.edit_jqxjtime); + edit_xhtime = this.findViewById(R.id.edit_xhtime); + bt_save = this.findViewById(R.id.bt_save); + bt_start = this.findViewById(R.id.bt_start); + qsmode = this.findViewById(R.id.qsmode); + progress_bar = this.findViewById(R.id.progress_bar); +// progress_text = this.findViewById(R.id.progress_text); //通过Activity.getIntent()获取当前页面接收到的Intent。 getXxxExtra方法获取Intent传递过来的数据 String msg=getIntent().getStringExtra("data"); gongneng_title.setText(msg); - ((TextView)this.findViewById(R.id.test_view)).setText(msg); + } /** @@ -54,6 +88,68 @@ public class zdqx_activity extends AppCompatActivity implements View.OnClickList */ private void initEvents() { gongneng_fanhui.setOnClickListener(this); + bt_save.setOnClickListener(this); + bt_start.setOnClickListener(this); + qsmode.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + new Thread(new Runnable() { + @Override + public void run() { + try { + DeviceData.Get().setCleaningMode(isChecked,null);//设置清洗模式 + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + } + + private void InitData(){ + + edit_pstime.setText(String.valueOf(DeviceData.Get().getDrainageTime()));//排水 + edit_jstime.setText(String.valueOf(DeviceData.Get().getInletTime()));//进水 + edit_jqxjtime.setText(String.valueOf(DeviceData.Get().getAddCleaningAgentTime()));//加清洗剂时间 + edit_xhtime.setText(String.valueOf(DeviceData.Get().getCyclicCleaningTime()));//循环清洗 + qsmode.setChecked(DeviceData.Get().getCleaningMode()); + progress_bar.setProgress(0); + //progress_bar.setIndeterminate(true); // 将进度条设置为不确定状态 + } + + + /** + * 监听外部数据变化 + */ + private void startListening(){ + new Thread(new Runnable() { + @Override + public void run() { + while (true) { + try { + if (SetValue(mValue,DeviceData.Get().getCleaningMode())) { + runOnUiThread(new Runnable() { + @Override + public void run() { + progress_bar.setIndeterminate(false);//停止旋转 + progress_bar.setProgress(100);//进度条设置为100% + bt_start.setText("清洗完成"); + // T.show(zdqx_activity.this,"清洗完成"); + } + }); + } + + Thread.sleep(1000); + + + }catch (Exception e) { + + } + } + } + }).start(); } //endregion @@ -69,7 +165,81 @@ public class zdqx_activity extends AppCompatActivity implements View.OnClickList case R.id.gongneng_fanhui://返回按钮 this.finish(); break; + case R.id.bt_save://保存 + new Thread(new Runnable() { + @Override + public void run() { + try { + if (!edit_pstime.getText().toString().equals("")) { + DeviceData.Get().setDrainageTime(Short.parseShort(edit_pstime.getText().toString()),null); + Thread.sleep(200); + } + if (!edit_jstime.getText().toString().equals("")) { + DeviceData.Get().setInletTime(Short.parseShort(edit_jstime.getText().toString()),null); + Thread.sleep(200); + } + if (!edit_jqxjtime.getText().toString().equals("")) { + DeviceData.Get().setAddCleaningAgentTime(Short.parseShort(edit_jqxjtime.getText().toString()),null); + Thread.sleep(200); + } + if (!edit_xhtime.getText().toString().equals("")) { + DeviceData.Get().setCyclicCleaningTime(Short.parseShort(edit_xhtime.getText().toString()),null); + Thread.sleep(200); + } + }catch (InterruptedException e) { + + }catch (Exception e) { + + } + + } + }); + break; + case R.id.bt_start://开始清洗 + new Thread(new Runnable() { + @Override + public void run() { + try { + DeviceData.Get().setStartCleaning(new IWriteCallBack() { + @Override + public void onSuccess() { + //UI线程操作UI控件 + runOnUiThread(new Runnable() { + @Override + public void run() { + progress_bar.setVisibility(View.VISIBLE); + progress_bar.setIndeterminate(true);//进度条开始旋转 + bt_start.setText("开始清洗"); + } + }); + } + + @Override + public void onFailure(String ErrorMsg) { + + } + }); + + } catch (Exception e) { + + } + + } + }); + break; } } //endregion + + //判断boolen 从fales变成true + private boolean SetValue(boolean value, boolean newValue) { + boolean mflag = value; + + if (newValue && !mflag) { // 当新值为 true 且前一个值为 false 时,发出通知 + value = newValue; // 更新标志变量的值 + return true; + } + value = newValue; // 更新标志变量的值 + return false; + } } \ No newline at end of file diff --git a/app/src/main/res/drawable/bt_circular.xml b/app/src/main/res/drawable/bt_circular.xml new file mode 100644 index 0000000..e416a84 --- /dev/null +++ b/app/src/main/res/drawable/bt_circular.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/btn_greenblue.xml b/app/src/main/res/drawable/btn_greenblue.xml new file mode 100644 index 0000000..a104f48 --- /dev/null +++ b/app/src/main/res/drawable/btn_greenblue.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/lcbg_border.xml b/app/src/main/res/drawable/lcbg_border.xml index 826d326..37958c2 100644 --- a/app/src/main/res/drawable/lcbg_border.xml +++ b/app/src/main/res/drawable/lcbg_border.xml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/app/src/main/res/drawable/qs_switch.xml b/app/src/main/res/drawable/qs_switch.xml new file mode 100644 index 0000000..42f7775 --- /dev/null +++ b/app/src/main/res/drawable/qs_switch.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/qs_textcolor.xml b/app/src/main/res/drawable/qs_textcolor.xml new file mode 100644 index 0000000..1cebad7 --- /dev/null +++ b/app/src/main/res/drawable/qs_textcolor.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/settingbutton.xml b/app/src/main/res/drawable/settingbutton.xml index cbda649..aa9397f 100644 --- a/app/src/main/res/drawable/settingbutton.xml +++ b/app/src/main/res/drawable/settingbutton.xml @@ -17,7 +17,9 @@ + + diff --git a/app/src/main/res/layout/from/layout/activity_zdqx.xml b/app/src/main/res/layout/from/layout/activity_zdqx.xml index 2ed7c57..a652db0 100644 --- a/app/src/main/res/layout/from/layout/activity_zdqx.xml +++ b/app/src/main/res/layout/from/layout/activity_zdqx.xml @@ -75,17 +75,188 @@ android:layout_alignParentRight="true" android:layout_alignParentBottom="true" android:src="@mipmap/yx"/> - - + + - - + android:layout_gravity="center" + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +