From e863cc5da7b0c581c65d7e16ac3aa2ff9d98e4fc Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期四, 20 三月 2025 11:46:20 +0800 Subject: [PATCH] feat(generallibrary): 添加项目选择功能 --- app/src/main/java/com/dayu/recharge/MyApplication.java | 284 +++++++++++++------------------------------------------- 1 files changed, 68 insertions(+), 216 deletions(-) diff --git a/app/src/main/java/com/dayu/recharge/MyApplication.java b/app/src/main/java/com/dayu/recharge/MyApplication.java index da04377..1aa6969 100644 --- a/app/src/main/java/com/dayu/recharge/MyApplication.java +++ b/app/src/main/java/com/dayu/recharge/MyApplication.java @@ -1,247 +1,99 @@ package com.dayu.recharge; +import android.app.Activity; import android.app.Application; -import android.os.Handler; -import android.os.Message; +import android.content.Context; +import android.content.Intent; import android.text.TextUtils; -import android.util.Log; -import com.dayu.recharge.dao.BaseDaoSingleton; -import com.dayu.recharge.dbBean.DeviceNumber; -import com.dayu.recharge.dbBean.IpBean; -import com.dayu.recharge.utils.ToastUtil; -import com.easysocket.EasySocket; -import com.easysocket.config.EasySocketOptions; -import com.easysocket.entity.SocketAddress; +import com.dayu.baselibrary.BaseApplication; +import com.dayu.baselibrary.business.BusinessProvider; +import com.dayu.baselibrary.business.StartLoginNavigotor; +import com.dayu.baselibrary.dao.BaseDaoSingleton; +import com.dayu.baselibrary.dbbean.LibraryBean; +import com.dayu.baselibrary.utils.BaseCommon; +import com.dayu.henanlibrary.HeNanApplication; +import com.dayu.henanlibrary.dao.HNBaseDaoSingleton; +import com.dayu.henanlibrary.dbBean.AdminDataBean; +import com.dayu.qihealonelibrary.QHAloneApplication; +import com.dayu.qiheonlinelibrary.QHOnLineApplication; +import com.dayu.recharge.activity.LoginActivity; import com.tencent.bugly.crashreport.CrashReport; -import com.dayu.recharge.net.ScoketMessageProtocol; -import com.dayu.recharge.net.SocketCallBack; -import com.dayu.recharge.net.SocketData; -import com.dayu.recharge.net.SocketNet; -import com.dayu.recharge.socketBean.ConfirmMachineRequestBean; -import com.dayu.recharge.socketBean.InitMachineBackBean; -import com.dayu.recharge.socketBean.InitMachineRequestBean; -import com.dayu.recharge.tools.BcdUtil; -import com.dayu.recharge.tools.HexUtil; -import com.dayu.recharge.utils.AidlUtil; -import com.dayu.recharge.utils.CRC8; -import com.dayu.recharge.utils.SocketUtil; -import com.dayu.recharge.utils.TipUtil; +import java.io.File; -import java.util.Arrays; -import java.util.Timer; -import java.util.TimerTask; +public class MyApplication extends Application implements StartLoginNavigotor { + public static String TAG = "MyApplication"; -public class MyApplication extends Application { - + //褰撳墠鍔犺浇鐨刲ibrary妯″潡 //0锛氭渤鍗楃増鏈紝1榻愭渤鍗曟満鐗� + public int libraryType = BaseCommon.NoLibrary; public static MyApplication myApplication; - private String address; - - SocketNet.CreateBack createBack; - //鏄惁姝e湪璇锋眰鍒濆鍖栨帴鍙� - public boolean isDoInitMachine = false; - //鏄惁杩炴帴鏈嶅姟鍣ㄦ垚鍔� - public boolean isConncet = false; - private final Timer timer = new Timer(); - @Override public void onCreate() { super.onCreate(); myApplication = this; - isAidl = true; - AidlUtil.getInstance().connectPrinterService(this); - initEasySocket(false, null); - - CrashReport.initCrashReport(getApplicationContext(), "45551598b8", true); - } - - private boolean isAidl; - - public boolean isAidl() { - return isAidl; - } - - public void setAidl(boolean aidl) { - isAidl = aidl; - } - - public IpBean ipBean; - - /** - * 鍒濆鍖朎asySocket - */ - public void initEasySocket(boolean isCreate, SocketNet.CreateBack createBack) { try { - this.createBack = createBack; - ipBean = BaseDaoSingleton.getInstance(MyApplication.myApplication).ipDao().findFirst(); - if (ipBean == null) { - ipBean = new IpBean(); - ipBean.setIp("dayuyanjiuyuan.top"); - ipBean.setPort(8888); - } - if (ipBean != null) { - try { - //澶勭悊褰撹繛鎺ヤ笂IP鍚庝慨鏀筰p涓嶇敓鏁堥棶棰� - if (EasySocket.getInstance().getDefconnection() != null) { - SocketAddress address = EasySocket.getInstance().getDefconnection().getOptions().getSocketAddress(); - if (address != null) { - if (!address.getIp().equals(ipBean.getIp()) || address.getPort() != ipBean.getPort()) { - EasySocket.getInstance().destroyConnection(); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } - - if (!SocketUtil.isInteger(ipBean.getIp())) { - //鍩熷悕鏂瑰紡 - SocketUtil.parseHostGetIPAddress(ipBean.getIp(), new Handler() { - @Override - public void handleMessage(Message msg) { - super.handleMessage(msg); - switch (msg.what) { - case 1: - createSocket(msg.obj + "", ipBean.getPort()); - break; - case 2: - ToastUtil.show("DNS瑙f瀽澶辫触"); - break; - } - - } - }); - - } else { - //ip鏂瑰紡 - if (EasySocket.getInstance().getContext() == null || isCreate) { - createSocket(ipBean.getIp(), ipBean.getPort()); - } else { - if (EasySocket.getInstance().getDefconnection() != null) { - SocketAddress address = EasySocket.getInstance().getDefconnection().getOptions().getSocketAddress(); - if (address != null) { - if (!address.getIp().equals(ipBean.getIp()) || address.getPort() != ipBean.getPort()) { - EasySocket.getInstance().destroyConnection(); - } - } - } - } - - } + File file = new File(HNBaseDaoSingleton.SqlitePath); + if (!file.exists()) { + file.mkdirs(); } } catch (Exception e) { e.printStackTrace(); } + initApplication(); + BaseApplication.getInstance().onCreat(this); + CrashReport.initCrashReport(getApplicationContext(), "45551598b8", true); } - /** - * 鍏呭�肩鐞嗘満娉ㄥ唽 - */ - public void initMachineRequestBean(String ip, int port, String addressCode) { - if (!TextUtils.isEmpty(ip) - && !TextUtils.isEmpty(String.valueOf(port)) - && !TextUtils.isEmpty(addressCode)) { - if (EasySocket.getInstance().getDefconnection() != null) { - isDoInitMachine = true; - InitMachineRequestBean initMachineRequestBean = new InitMachineRequestBean(); - initMachineRequestBean.setControl("01"); - //130107200008 112 闈掓硥灞呭浼� - initMachineRequestBean.setAddress(addressCode); - initMachineRequestBean.setXuLie(SocketUtil.getXuLie(this)); - initMachineRequestBean.setAFN("91"); -// - Log.i("Socket", "娉ㄥ唽鎶ユ枃"); - SocketNet.getInstance().sendTestMessage(initMachineRequestBean.pack(), new SocketCallBack() { - @Override - public void onSocketResponse(SocketData readData) { - - if (CRC8.isCRC8(readData.getOriginDataBytes())) { - //鏍¢獙CRC鎴愬姛 - InitMachineBackBean initMachineBackBean = new InitMachineBackBean(); - - String initCode = HexUtil.bytesToHex(Arrays.copyOfRange(readData.getBodyBytes(), 2, 18)); - //纭鏀跺埌娉ㄥ唽鍙锋姤鏂� - ConfirmMachineRequestBean confirmMachineRequestBean = new ConfirmMachineRequestBean(); - confirmMachineRequestBean.setControl("01"); - //130107200008 112 闈掓硥灞呭浼� - confirmMachineRequestBean.setAddress(addressCode); - confirmMachineRequestBean.setXuLie(SocketUtil.getXuLie(MyApplication.this)); - confirmMachineRequestBean.setAFN("92"); - confirmMachineRequestBean.setInitCode(initCode); - Log.i("Socket", "纭娉ㄥ唽鎶ユ枃"); - SocketNet.getInstance().sendTestMessage(confirmMachineRequestBean.pack(), new SocketCallBack() { - - @Override - public void onSocketResponse(SocketData readData) { - isDoInitMachine = false; - if (CRC8.isCRC8(readData.getOriginDataBytes())) { - byte stateByte = readData.getBodyBytes()[2]; - String state = BcdUtil.bcdToStr(stateByte); - //BCD鐮�00鎴愬姛01澶辫触(娉ㄥ唽鍙蜂笉鏄湇鍔″櫒杩斿洖淇℃伅) - if (state.equalsIgnoreCase("00")) { - //淇濆瓨璁惧娉ㄥ唽鍙� - DeviceNumber deviceNumber = BaseDaoSingleton.getInstance(MyApplication.myApplication).deviceNumberDao().findFirst(); - if (deviceNumber != null) { - deviceNumber.setDeviceRegistrationNumber(initCode); - } else { - deviceNumber = new DeviceNumber(); - deviceNumber.setDeviceRegistrationNumber(initCode); - } - BaseDaoSingleton.getInstance(MyApplication.myApplication).deviceNumberDao().insert(deviceNumber); - -// WSHelper.getInstance(MyApplication.this).put("initCode", initCode); - ToastUtil.show("鍏呭�肩鐞嗘敞鍐屾姤鏂囪幏鍙栨垚鍔�"); - } else { - //鏍¢獙CRC閿欒 - ToastUtil.show("纭鏀跺埌娉ㄥ唽鎶ユ枃鐘舵�佸け璐�"); - } - } else { - //鏍¢獙CRC閿欒 - ToastUtil.show("纭鏀跺埌娉ㄥ唽鎶ユ枃鏍¢獙CRC閿欒"); - } - } - - @Override - public void onSocketError(int code, String msg) { - - } - }); - } else {//鏍¢獙CRC閿欒 - ToastUtil.show("鍏呭�肩鐞嗘敞鍐屾姤鏂囨牎楠孋RC閿欒"); - } - } - - @Override - public void onSocketError(int code, String msg) { - - } - }); - + public void initApplication() { + //鍏煎鑰佺増鐨勶紝璁や负鏈塧ddressCode骞朵笖LibraryBean涓簄ull鐨勪负娌冲崡鐗堟湰鐨� + try { + AdminDataBean adminDataBean = HNBaseDaoSingleton.getInstance(this).adminDao().findFirst(); + LibraryBean libraryBean = BaseDaoSingleton.getInstance(this).libraryDao().findFirst(); + if (adminDataBean != null && libraryBean == null && !TextUtils.isEmpty(adminDataBean.addressCode)) { + libraryType = BaseCommon.HeNanLibrary; + initHeNan(); + } else if (libraryBean != null) { + libraryType = libraryBean.getType(); + switch (libraryType) { + case BaseCommon.HeNanLibrary: + initHeNan(); + break; + case BaseCommon.QHAloneLibrary: + QHAloneApplication.getInstance().application = this; + break; + case BaseCommon.QHOnLineLibrary: + QHOnLineApplication.getInstance(this); + BusinessProvider.getInstance(this); + break; + case BaseCommon.Generalv1Library: + com.dayu.general.BaseApplication.getInstance(this); + break; + } } - - + } catch ( + Exception e) { + e.printStackTrace(); + CrashReport.postCatchedException(e); } } - private void createSocket(String ip, int port) { - // socket閰嶇疆 - EasySocketOptions options = new EasySocketOptions.Builder() - // 涓绘満鍦板潃锛岃濉啓鑷繁鐨処P鍦板潃锛屼互getString鐨勬柟寮忔槸涓轰簡闅愯棌浣滆�呰嚜宸辩殑IP鍦板潃 - .setSocketAddress(new SocketAddress(ip, port)) - // 瀹氫箟娑堟伅鍗忚锛屾柟渚胯В鍐� socket榛忓寘銆佸垎鍖呯殑闂 - .setReaderProtocol(new ScoketMessageProtocol()) - .setMaxWriteBytes(150) - .setMaxReadBytes(150) - .setRequestTimeout(5 * 1000) - .build(); + /** + * 鍒濆鍖栨渤鍗� + */ + private void initHeNan() { + HeNanApplication.getInstance().application = this; + HeNanApplication.getInstance().initEasySocket(false, null); + } - // 鍒濆鍖� - EasySocket.getInstance().createConnection(options, this);// 鍒涘缓涓�涓猻ocket杩炴帴 -// EasySocket.getInstance().subscribeSocketAction(socketActionListener); - EasySocket.getInstance().subscribeSocketAction(SocketNet.getInstance().socketNet.socketActionListener); + + @Override + public void navigateToLogin(Context context) { + Intent intent = new Intent(context, LoginActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + context.startActivity(intent); } -- Gitblit v1.8.0