From d0e49b8c045e09e96cc875b27033b4bfcf07438f Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期二, 29 四月 2025 20:50:37 +0800 Subject: [PATCH] 2025年04月29日20:50:35 --- app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMPSDKManager.java | 118 ++++++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 80 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMPSDKManager.java b/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMPSDKManager.java index c434570..e4b9dd2 100644 --- a/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMPSDKManager.java +++ b/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMPSDKManager.java @@ -1,25 +1,36 @@ package com.hdl.photovoltaic.uni; +import android.app.ActivityManager; import android.app.Application; import android.content.Context; +import android.os.Build; import android.os.Environment; +import android.os.Process; import android.text.TextUtils; +import android.util.Log; import com.google.gson.Gson; +import com.hdl.linkpm.sdk.user.HDLLinkPMUser; import com.hdl.photovoltaic.HDLApp; import com.hdl.photovoltaic.R; import com.hdl.photovoltaic.config.AppConfigManage; +import com.hdl.photovoltaic.config.UserConfigManage; +import com.hdl.photovoltaic.enums.LowerTagType; import com.hdl.photovoltaic.other.HdlLogLogic; import com.hdl.photovoltaic.other.HdlThreadLogic; +import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; +import org.greenrobot.eventbus.EventBus; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.util.HashMap; +import java.util.List; import io.dcloud.common.DHInterface.ICallBack; +import io.dcloud.common.util.RuningAcitvityUtil; import io.dcloud.feature.sdk.DCSDKInitConfig; import io.dcloud.feature.sdk.DCUniMPSDK; import io.dcloud.feature.sdk.Interface.IDCUniMPPreInitCallback; @@ -27,10 +38,15 @@ import io.dcloud.feature.sdk.Interface.IUniMP; import io.dcloud.feature.sdk.Interface.IUniMPOnCloseCallBack; import io.dcloud.feature.unimp.DCUniMPJSCallback; +import io.dcloud.feature.unimp.config.UniMPOpenConfiguration; public class HDLUniMPSDKManager { private static final String TAG = "HDLUniMPSDKManager"; + /** + * 鏍囪鐧诲綍鐣岄潰鏄惁宸茬粡瀛樺湪 + */ + public static boolean isExistsActivity = false; /** * context */ @@ -89,18 +105,20 @@ private void removeCallBack() { DCUniMPSDK.getInstance().setUniMPOnCloseCallBack(null); DCUniMPSDK.getInstance().setOnUniMPEventCallBack(null); + } /** * 鐩戝惉鐩稿叧鍥炶皟 */ private void registerCallBack() { + DCUniMPSDK.getInstance(); //1.璁剧疆灏忕▼搴忚鍏抽棴浜嬩欢鐩戝惉 DCUniMPSDK.getInstance().setUniMPOnCloseCallBack(new IUniMPOnCloseCallBack() { @Override public void onClose(String appid) { if (AppConfigManage.isDebug()) { - HdlLogLogic.print(TAG, "鏀跺埌灏忕▼搴忛�氱煡 琚叧闂簡"); + HdlLogLogic.print("鏀跺埌灏忕▼搴忛�氱煡 琚叧闂簡"); } //灏忕▼搴忚鍏抽棴闇�瑕佸瀹炰緥缂撳瓨鍒犻櫎鎿嶄綔 if (mUniMPCaches.containsKey(appid)) { @@ -110,6 +128,13 @@ if (appid.equals(mCurrentAppId)) { mCurrentAppId = ""; } + + //灏忕▼搴忚鍏抽棴浜嗛�氱煡缁欏師鐢� + BaseEventBus baseEventBus = new BaseEventBus(); + baseEventBus.setTopic(HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE); + baseEventBus.setType(LowerTagType.power_station.toString()); + EventBus.getDefault().post(baseEventBus); + } }); @@ -118,9 +143,12 @@ @Override public void onUniMPEventReceive(String appid, String event, Object data, DCUniMPJSCallback callback) { // handelUniMPEventReceive(appid, event, data, callback); - HdlLogLogic.print(TAG, "鏀跺埌灏忕▼搴忛�氱煡 event=" + event); + HdlLogLogic.print("鏀跺埌灏忕▼搴忛�氱煡 event=" + event); +// String processMessage = Process.myPid() + " "; +// HdlLogLogic.print("杩涚▼淇℃伅锛�" + processMessage); //鏆傛椂閫氳繃杩欎釜澶勭悊灏忕▼搴忓悓鏃跺鏉$浉鍚岀殑璇锋眰 if (data == null) { + HdlLogLogic.print("鏀跺埌灏忕▼搴忛�氱煡,data鏁版嵁涓簄ull銆�", true); return; } // String key= MD5Utils.getMd5(event+data.toString()); @@ -136,11 +164,19 @@ //鍥炰紶鏁版嵁缁欏皬绋嬪簭 JSONObject params = getAppParams(); callback.invoke(params); - HdlLogLogic.print(TAG, "uni_GetAppParams callback:" + params.toString()); + HdlLogLogic.print("uni_GetAppParams callback:" + params.toString()); } else { //闄や簡缁熶竴澶勭悊锛屽墿浣欏叾瀹冪壒瀹氬満鏅殑浜嬩欢閫氱煡 if (onOtherUniMPEventCallBack != null) { onOtherUniMPEventCallBack.onOtherUniMPEventReceive(appid, event, data, callback); + } else { + if (!HDLUniMPSDKManager.isExistsActivity) { + HDLUniMPSDKManager.isExistsActivity = true; + HdlLogLogic.print("鏀跺埌灏忕▼搴忛�氱煡,鍥炶皟浜嬩欢涓簄ull,鏃犳硶鍥炶皟浜嬩欢骞舵墽琛屼笟鍔¢�昏緫---event=" + event + "\r\n" + "data=" + data, true); + //鏈夊彲鑳芥槸绯荤粺鍥炴敹鎺塧ctivity瀵艰嚧鍥炶皟涓簄ull锛岃繖鏍锋儏鍐典笅寮哄埗杩斿洖鐧诲綍鐣岄潰锛� + //todo 闀挎椂闂存病鍝嶅簲灏嗛��鍑虹櫥褰曠晫闈㈤噸鏂扮櫥褰� + HDLLinkPMUser.getInstance().logout(0); + } } } } @@ -184,12 +220,12 @@ public void checkUniMPResource(String uniAppId) { //2.涓嶆槸绗竴娆″惎鍔ㄤ簡锛屽厛鍒ゆ柇wgt鍖呬箣鍓嶆湁涔堟湁閮ㄧ讲杩� if (!DCUniMPSDK.getInstance().isExistsApp(uniAppId)) { - HdlLogLogic.print(TAG, "DCUni wgt涔嬪墠杩樻病閮ㄧ讲杩�"); + HdlLogLogic.print("DCUni wgt涔嬪墠杩樻病閮ㄧ讲杩�"); //涔嬪墠娌¢儴缃茶繃閲嶆柊閮ㄧ讲 hdlReleaseAppResourceToRunPathWithAppid(uniAppId); // [self hdlReleaseAppResourceToRunPathWithAppid:uniAppId]; } else { - HdlLogLogic.print(TAG, "DCUni wgt宸茬粡閮ㄧ讲杩�"); + HdlLogLogic.print("DCUni wgt宸茬粡閮ㄧ讲杩�"); } } @@ -202,7 +238,7 @@ String wgtPath = mContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) + "/" + uniAppId + ".wgt"; boolean b = fileIsExists(wgtPath); if (b) { - HdlLogLogic.print(TAG, "wgt鍖呮湰鍦板瓨鍦�"); + HdlLogLogic.print("wgt鍖呮湰鍦板瓨鍦�"); DCUniMPSDK.getInstance().releaseWgtToRunPathFromePath(uniAppId, wgtPath, new ICallBack() { @Override public Object onCallBack(int code, Object pArgs) { @@ -211,13 +247,13 @@ } else { //閲婃斁wgt澶辫触 - HdlLogLogic.print(TAG, "璧勬簮閲婃斁澶辫触"); + HdlLogLogic.print("璧勬簮閲婃斁澶辫触"); } return null; } }); } else { - HdlLogLogic.print(TAG, "wgt鍖呮湰鍦颁笉瀛樺湪"); + HdlLogLogic.print("wgt鍖呮湰鍦颁笉瀛樺湪"); } } @@ -240,18 +276,10 @@ return true; } - /** - * 鎵撳紑灏忕▼搴� - * - * @param uniAppId 灏忕▼搴廔D - * @param path 鎸囧畾璺緞 - * 渚嬶細pages/component/scroll-view/scroll-view?a=1&b=2&c=3 - * @param callBack 鐩戝惉灏忕▼搴廜therUniMPEvent浜嬩欢 - */ - public void openUniMP(String uniAppId, String path, IOnOtherUniMPEventCallBack callBack) { + public void openUniMP(String uniAppId, String path, JSONObject jsonObject, IOnOtherUniMPEventCallBack callBack) { if (TextUtils.isEmpty(uniAppId)) { HdlThreadLogic.toast(mContext, "uni Id null"); - HdlLogLogic.print(TAG, "灏忕▼搴廔D 涓嶈兘涓虹┖"); + HdlLogLogic.print("灏忕▼搴廔D 涓嶈兘涓虹┖"); return; } try { @@ -260,17 +288,30 @@ if (TextUtils.isEmpty(path)) { uniMP = DCUniMPSDK.getInstance().openUniMP(mContext, uniAppId); } else { -// UniMPOpenConfiguration uniMPOpenConfiguration = new UniMPOpenConfiguration(); -// uniMPOpenConfiguration.path = path; - uniMP = DCUniMPSDK.getInstance().openUniMP(mContext, uniAppId, path); + UniMPOpenConfiguration uniMPOpenConfiguration = new UniMPOpenConfiguration(); + uniMPOpenConfiguration.path = path; + uniMPOpenConfiguration.extraData = jsonObject; + if (UserConfigManage.getInstance().getUniBottomSafeDistanceBackgroundColor() == 0) { + uniMPOpenConfiguration.splashClass = CSplashView.class; + } else { + uniMPOpenConfiguration.splashClass = BSplashView.class; + } + uniMP = DCUniMPSDK.getInstance().openUniMP(mContext, uniAppId, uniMPOpenConfiguration); } +// //android14鏈変簺璁惧鏈夐棶棰橈紝闇�瑕佺瓑寰� +// if (android.os.Build.VERSION.SDK_INT >= 34) { +// if (TextUtils.isEmpty(mCurrentAppId)) { +// //绗竴娆$敤瑕佷紤鐪� +// SystemClock.sleep(1000); +// } +// } mCurrentAppId = uniAppId;//璁板綍褰撳墠灏忕▼搴� mUniMPCaches.put(uniMP.getAppid(), uniMP); } catch (Exception e) { e.printStackTrace(); HdlThreadLogic.toast(HDLApp.getInstance(), R.string.uni_open_error); - initDCUniMPSDK(HDLApp.getInstance()); - HdlLogLogic.print(TAG, "鎵撳紑澶辫触" + e.getMessage()); +// initDCUniMPSDK(HDLApp.getInstance()); + HdlLogLogic.print("鎵撳紑澶辫触===" + e.getMessage()); } } @@ -289,7 +330,7 @@ @Override public void onInitFinished(boolean b) { - HdlLogLogic.print("unimp", "UniMPSDK 鍒濆鍖栧畬鎴�----" + b); + HdlLogLogic.print("UniMPSDK 鍒濆鍖栧畬鎴�----" + b); } }); @@ -312,19 +353,19 @@ */ public void openUniMP(String uniAppId, JSONObject arguments, IOnOtherUniMPEventCallBack callBack) { if (TextUtils.isEmpty(uniAppId)) { - HdlLogLogic.print(TAG, "灏忕▼搴廔D 涓嶈兘涓虹┖"); + HdlLogLogic.print("灏忕▼搴廔D 涓嶈兘涓虹┖"); return; } try { setOnOtherUniMPEventCallBack(callBack); -// UniMPOpenConfiguration uniMPOpenConfiguration = new UniMPOpenConfiguration(); -// uniMPOpenConfiguration.extraData = arguments; - uniMP = DCUniMPSDK.getInstance().openUniMP(mContext, uniAppId, arguments); + UniMPOpenConfiguration uniMPOpenConfiguration = new UniMPOpenConfiguration(); + uniMPOpenConfiguration.extraData = arguments; + uniMP = DCUniMPSDK.getInstance().openUniMP(mContext, uniAppId, uniMPOpenConfiguration); mCurrentAppId = uniAppId;//璁板綍褰撳墠灏忕▼搴� mUniMPCaches.put(uniMP.getAppid(), uniMP); } catch (Exception e) { e.printStackTrace(); - HdlLogLogic.print(TAG, "鎵撳紑澶辫触" + e.getMessage()); + HdlLogLogic.print("鎵撳紑澶辫触===" + e.getMessage()); } } @@ -333,20 +374,20 @@ * 娉ㄦ剰锛氶渶瑕佹彁鍓嶅皬绋嬪簭鍦ㄨ繍琛屾墠鍙垚鍔� * * @param uniAppId 灏忕▼搴忔寚瀹� - * @param event 灏忕▼搴忔寚瀹氫富棰� + * @param topic 灏忕▼搴忔寚瀹氫富棰� * @param data String鎴朖SON */ - public void sendUniMPEvent(String uniAppId, String event, Object data) { + public void sendUniMPEvent(String uniAppId, String topic, Object data) { if (mUniMPCaches.containsKey(uniAppId)) { if (mUniMPCaches.get(uniAppId) != null) { - mUniMPCaches.get(uniAppId).sendUniMPEvent(event, data); - HdlLogLogic.print(TAG, "鍙戦�侀�氱煡鎴愬姛锛歟vent锛�" + event + " data锛�" + new Gson().toJson(data)); + mUniMPCaches.get(uniAppId).sendUniMPEvent(topic, data); +// HdlLogLogic.print("Android---閫氱煡---uni---涓婚:" + topic + "---鍙戦�佹暟鎹�:" + new Gson().toJson(data)); } else { - HdlLogLogic.print(TAG, "鍙戦�佸け璐ワ紝灏忕▼搴忓璞′负绌猴細" + uniAppId); +// HdlLogLogic.print("Android---閫氱煡---uni---澶辫触---灏忕▼搴忓璞′负绌�:" + uniAppId); } } else { - HdlLogLogic.print(TAG, "鍙戦�佸け璐ワ紝鎵句笉鍒板搴旂殑灏忕▼搴忥細" + uniAppId); +// HdlLogLogic.print("Android---閫氱煡---uni---澶辫触---卢灏忕▼搴忓璞′负绌�:" + uniAppId); } } @@ -360,7 +401,7 @@ */ public void sendUniMPEventToCurrentOpenAppId(String event, Object data) { if (TextUtils.isEmpty(mCurrentAppId)) { - HdlLogLogic.print(TAG, "褰撳墠娌℃墦寮�鐨勫皬绋嬪簭"); + HdlLogLogic.print("褰撳墠娌℃墦寮�鐨勫皬绋嬪簭"); return; } sendUniMPEvent(mCurrentAppId, event, data); @@ -388,7 +429,7 @@ public void setOnOtherUniMPEventCallBack(IOnOtherUniMPEventCallBack onOtherUniMPEventCallBack) { this.onOtherUniMPEventCallBack = onOtherUniMPEventCallBack; - HdlLogLogic.print("onOtherUniMPEventCallBack", "set callback"); + HdlLogLogic.print("onOtherUniMPEventCallBack set callback"); } /** @@ -397,9 +438,10 @@ * @param onOtherUniMPEventCallBack - */ public void checkRemoveOtherUniMPEventCallBack(IOnOtherUniMPEventCallBack onOtherUniMPEventCallBack) { + HdlLogLogic.print("onOtherUniMPEventCallBack", true); if (this.onOtherUniMPEventCallBack == onOtherUniMPEventCallBack) { this.onOtherUniMPEventCallBack = null; - HdlLogLogic.print("onOtherUniMPEventCallBack", "remove callback"); + HdlLogLogic.print("onOtherUniMPEventCallBack remove callback", true); } } -- Gitblit v1.8.0