app/src/main/java/com/dayu/recharge/MyApplication.java
@@ -43,6 +43,9 @@ public boolean isConncet = false; private final Timer timer = new Timer(); //每次启动程序只去注册一遍,不再重新注册。 public static boolean isCreate = false; @Override public void onCreate() { @@ -77,12 +80,14 @@ try { ipBean = BaseDaoSingleton.getInstance(MyApplication.myApplication).ipDao().findFirst(); } catch (Exception e) { e.printStackTrace(); e.printStackTrace(); } if (ipBean == null) { ipBean = new IpBean(); ipBean.setIp("newreceive.hnsjgg.com"); ipBean.setPort(9999); // ipBean.setIp("dayuyanjiuyuan.top"); // ipBean.setPort(8888); } if (ipBean != null) { try { @@ -183,6 +188,7 @@ @Override public void onSocketResponse(SocketData readData) { isDoInitMachine = false; MyApplication.myApplication.isCreate = true; if (CRC8.isCRC8(readData.getOriginDataBytes())) { byte stateByte = readData.getBodyBytes()[2]; String state = BcdUtil.bcdToStr(stateByte); app/src/main/java/com/dayu/recharge/activity/BaseActivity.java
@@ -16,6 +16,7 @@ import com.dayu.recharge.dao.AppDatabase; import com.dayu.recharge.dao.BaseDaoSingleton; import com.dayu.recharge.view.TitleBar; import com.easysocket.EasySocket; /** * Created by zuoxiao on 2018/12/20. @@ -45,6 +46,11 @@ @Override protected void onResume() { super.onResume(); } @Override public void setContentView(View layoutResID) { super.setContentView(layoutResID); try { app/src/main/java/com/dayu/recharge/activity/HomeActivity.java
@@ -91,8 +91,8 @@ homeBinding.homeParameter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(HomeActivity.this, ParameterActivity.class)); PassWordDialog passWordDialog = new PassWordDialog(HomeActivity.this, new Intent(HomeActivity.this, ParameterActivity.class)); passWordDialog.show(); } }); homeBinding.homeMy.setOnClickListener(new View.OnClickListener() { app/src/main/java/com/dayu/recharge/activity/ReadCardAcitivy.java
@@ -71,6 +71,7 @@ redCardBinding.redName.setText("用户姓名:" + userName); redCardBinding.redRemainderBlance.setText("剩余金额:" + MornyUtil.changeF2Y(blance) + "元"); redCardBinding.redStatu.setText("卡状态:" + statu); redCardBinding.redAddressCode.setText("地址码:" + userCard.getAddressCode()); if (userCard != null) { redCardBinding.redInitCode.setText(userCard.getInitPeasantCode()); Calendar calendar = userCard.getRechargeDate(); app/src/main/java/com/dayu/recharge/net/SocketNet.java
@@ -111,7 +111,7 @@ if (!MyApplication.myApplication.isDoInitMachine) { Log.i("SocketActionListener1111", "isDoInitMachine"); if (MyApplication.myApplication.ipBean != null && adminData != null) { if (!TextUtils.isEmpty(adminData.getAddressCode())) { if (!TextUtils.isEmpty(adminData.getAddressCode()) && !MyApplication.myApplication.isCreate) { Log.i("SocketActionListener1111", "initMachineRequestBean"); MyApplication.myApplication.initMachineRequestBean(MyApplication.myApplication.ipBean.getIp(), MyApplication.myApplication.ipBean.getPort(), adminData.getAddressCode()); @@ -135,13 +135,10 @@ MyApplication.myApplication.isConncet = false; rushState(); Log.i("SocketActionListener", "socket连接失败"); if (isTest) { // ToastUtil.show(mContext, "连接失败,请检查网络"); } else { if (myCallBack != null) { myCallBack.onSocketError(-1, "连接数据中心失败,请检查网络"); } if (myCallBack != null) { myCallBack.onSocketError(-1, "连接数据中心失败,请检查网络"); } myCallBack = null; } /** @@ -154,8 +151,11 @@ Log.i("SocketActionListener", "---> socket断开连接,是否需要重连:" + isNeedReconnect); MyApplication.myApplication.isConncet = false; rushState(); if (myCallBack != null) { myCallBack.onSocketError(-2, "与服务器连接断开,请重试"); } myCallBack = null; } /** @@ -174,7 +174,7 @@ if (myCallBack != null) { myCallBack.onSocketResponse(socketData); } myCallBack = null; } }; app/src/main/res/layout/activity_red_card.xml
@@ -88,7 +88,13 @@ android:layout_marginTop="15dp" android:text="卡状态:" android:textSize="@dimen/text_size" /> <TextView android:id="@+id/red_addressCode" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:text="地址编码:" android:textSize="@dimen/text_size" /> </LinearLayout> </ScrollView> easysocket/build.gradle
@@ -23,6 +23,7 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) compileOnly 'com.google.code.gson:gson:2.2.4' compileOnly 'com.tencent.bugly:crashreport:4.1.9.3' } sourceCompatibility = "7" easysocket/src/main/java/com/easysocket/EasySocket.java
@@ -129,6 +129,7 @@ */ public EasySocket disconnect(boolean isNeedReconnect) { LogUtil.d("EasySocket--》disconnect"); if (defConnection != null) getDefconnection().disconnect(isNeedReconnect); return this; } easysocket/src/main/java/com/easysocket/connection/connect/TcpConnection.java
@@ -6,6 +6,7 @@ import com.easysocket.entity.SocketAddress; import com.easysocket.utils.LogUtil; import com.easysocket.utils.Utils; import com.tencent.bugly.crashreport.CrashReport; import java.io.IOException; import java.io.InputStream; @@ -122,6 +123,7 @@ return socket.getInputStream(); } catch (IOException e) { e.printStackTrace(); CrashReport.postCatchedException(e); } } return null; @@ -134,6 +136,7 @@ return socket.getOutputStream(); } catch (IOException e) { e.printStackTrace(); CrashReport.postCatchedException(e); } } return null; easysocket/src/main/java/com/easysocket/connection/dispatcher/CallbackResponseDispatcher.java
@@ -71,6 +71,7 @@ public void engineThread() { try { if (timeoutExecutor == null || timeoutExecutor.isShutdown()) { //创建一个只有一个线程的线程池。这个线程池会顺序执行提交的任务,并保证任务之间的顺序性。 timeoutExecutor = Executors.newSingleThreadExecutor(); timeoutExecutor.execute(new Runnable() { @Override easysocket/src/main/java/com/easysocket/connection/iowork/EasyReader.java
@@ -12,6 +12,7 @@ import com.easysocket.interfaces.io.IReader; import com.easysocket.utils.HexUtil; import com.easysocket.utils.LogUtil; import com.tencent.bugly.crashreport.CrashReport; import java.io.IOException; import java.io.InputStream; @@ -195,12 +196,12 @@ // 停止线程 stopThread = true; release(); CrashReport.postCatchedException(unrecoverableException); } catch (ReadRecoverableExeption readRecoverableExeption) { readRecoverableExeption.printStackTrace(); // 重连 LogUtil.d("--->重连 ReadRecoverableExeption"); connectionManager.disconnect(true); } catch (IOException e) { e.printStackTrace(); // 重连