diff --git a/.idea/misc.xml b/.idea/misc.xml index 0c26bd6..bcf7264 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,7 @@ - + diff --git a/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java b/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java index 79911e5..ec57d75 100644 --- a/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java +++ b/app/src/main/java/com/example/bpa/app/ModbusTcpServer.java @@ -3,6 +3,7 @@ package com.example.bpa.app; import com.example.bpa.Model.IReadCallBack; import com.example.bpa.Model.IWriteCallBack; +import com.example.bpa.config.DataBus; import com.example.bpa.helper.MessageLog; import com.licheedev.modbus4android.ModbusCallback; import com.licheedev.modbus4android.ModbusParam; @@ -116,6 +117,7 @@ public class ModbusTcpServer { @Override public void onSuccess(ModbusMaster modbusMaster) { MessageLog.ShowInfo("设备 " + host + " 连接成功"); + DataBus.getInstance().PlcIsConnect=true; //1.数据中心 DeviceData.Get().Init(); //2.业务线程 @@ -124,6 +126,7 @@ public class ModbusTcpServer { @Override public void onFailure(Throwable tr) { + DataBus.getInstance().PlcIsConnect=false; MessageLog.ShowError("设备 " + host + " 连接失败:" + tr.getMessage()); } diff --git a/app/src/main/java/com/example/bpa/config/DataBus.java b/app/src/main/java/com/example/bpa/config/DataBus.java index 91f0299..63389ec 100644 --- a/app/src/main/java/com/example/bpa/config/DataBus.java +++ b/app/src/main/java/com/example/bpa/config/DataBus.java @@ -35,6 +35,13 @@ public class DataBus { } //endregion + //region 连接状态 + /** + * Plc是否连接 + */ + public boolean PlcIsConnect=false; + //endregion + //region 数据中心 /** * 主界面商品列表 diff --git a/app/src/main/java/com/example/bpa/helper/FlashHelper.java b/app/src/main/java/com/example/bpa/helper/FlashHelper.java new file mode 100644 index 0000000..1848441 --- /dev/null +++ b/app/src/main/java/com/example/bpa/helper/FlashHelper.java @@ -0,0 +1,100 @@ +package com.example.bpa.helper; +import android.util.Log; +import android.view.View; +import android.view.animation.AlphaAnimation; +import android.view.animation.Animation; +import android.view.animation.LinearInterpolator; +import android.widget.EditText; + +import java.security.Key; +import java.util.ArrayList; +import java.util.List; + +/** + * Title:控件闪烁帮助类 + * Description: + *

+ * Created by pei + * Date: 2018/4/22 + */ +public class FlashHelper { + + private FlashHelper() {} + + private static class Holder { + private static FlashHelper instance = new FlashHelper(); + } + + public static FlashHelper getInstance() { + return FlashHelper.Holder.instance; + } + public List listviews = new ArrayList(); + public List listviews1 = new ArrayList(); + + /**开启View闪烁效果**/ + public void startFlick( View view ,Integer key) { + if (null == view) { + return; + } + if(!listviews.contains(key)) + { + view.setVisibility(View.VISIBLE); + Log.e("213", "VISIBLE: "); + Animation alphaAnimation = new AlphaAnimation(1, 0); + alphaAnimation.setDuration(300); + alphaAnimation.setInterpolator(new LinearInterpolator()); + alphaAnimation.setRepeatCount(Animation.INFINITE); + alphaAnimation.setRepeatMode(Animation.REVERSE); + view.startAnimation(alphaAnimation); + listviews.add(key); + } + } + + /**取消View闪烁效果**/ + public void stopFlick( View view ,Integer key ) { + if (null == view) { + return; + } + + if(listviews.contains(key)) + { + view.setVisibility(View.GONE); + view.clearAnimation(); + listviews.remove(key); + } + } + + /**开启View闪烁效果**/ + public void startFlick1( View view ,Integer key) { + if (null == view) { + return; + } + if(!listviews1.contains(key)) + { + view.setVisibility(View.VISIBLE); + Log.e("213", "VISIBLE: "); + Animation alphaAnimation = new AlphaAnimation(1, 0); + alphaAnimation.setDuration(300); + alphaAnimation.setInterpolator(new LinearInterpolator()); + alphaAnimation.setRepeatCount(Animation.INFINITE); + alphaAnimation.setRepeatMode(Animation.REVERSE); + view.startAnimation(alphaAnimation); + listviews1.add(key); + } + } + + /**取消View闪烁效果**/ + public void stopFlick1( View view ,Integer key ) { + if (null == view) { + return; + } + + if(listviews1.contains(key)) + { + view.setVisibility(View.GONE); + view.clearAnimation(); + listviews1.remove(key); + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/bpa/view/adapter/lc_item_adapter.java b/app/src/main/java/com/example/bpa/view/adapter/lc_item_adapter.java index 70de059..88846db 100644 --- a/app/src/main/java/com/example/bpa/view/adapter/lc_item_adapter.java +++ b/app/src/main/java/com/example/bpa/view/adapter/lc_item_adapter.java @@ -8,6 +8,7 @@ import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ImageView; +import android.widget.RelativeLayout; import android.widget.Spinner; import android.widget.TextView; @@ -73,24 +74,35 @@ public class lc_item_adapter extends RecyclerView.Adapter bpa_materials=new ArrayList<>(); //当前选中的料仓id lc_item_adapter.MyLCViewHolder currentSilo; - + //当前料仓集合 + List datas = new ArrayList(); //region 私有函数 @Override protected void onCreate(Bundle savedInstanceState) { @@ -66,6 +71,7 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList setContentView(R.layout.activity_lcsz); Init(); initEvents(); + Run(); } //endregion @@ -90,7 +96,6 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList //必须,防止recyclerview高度为wrap时测量item高度0 layout.setAutoMeasureEnabled(true); recyclerView.setLayoutManager(layout); - List datas = new ArrayList(); //获取料仓数据 ArrayList bpa_silos =QueryDB.GetSilosALL(); //加载materials数据 @@ -145,13 +150,11 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList listViewParent.setVisibility(View.VISIBLE); currentSilo = null; currentSilo = (lc_item_adapter.MyLCViewHolder) viewHolder; - } } @Override public void onItemLongClick(View view, int position) { - } })); //endregion @@ -207,22 +210,59 @@ public class lcsz_activity extends AppCompatActivity implements View.OnClickList //endregion - //region + //region 线程 + + /** + * 实时显示线程 + */ public void Run() { - ThreadManager.Get().StartLong("Plc设备数据监听", true, new IThread() { + new Thread(new Runnable() { @Override - public void Run() throws InterruptedException { - //获取实时值 + public void run() { + while (DataBus.getInstance().PlcIsConnect) { + try { + lcsz_activity.this.runOnUiThread(new Runnable() { + @Override + public void run() { + for (int i=0;i + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-xhdpi/bl.png b/app/src/main/res/mipmap-xhdpi/bl.png new file mode 100644 index 0000000..9522cd4 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/bl.png differ diff --git a/app/src/main/res/mipmap-xhdpi/gj.png b/app/src/main/res/mipmap-xhdpi/gj.png new file mode 100644 index 0000000..1a1ce57 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/gj.png differ