From ceaa1cd33a4eb03fa91376166d12549a8ddc971a Mon Sep 17 00:00:00 2001 From: tongchenfei Date: Thu, 24 Dec 2020 15:45:24 +0800 Subject: [PATCH 1/4] =?UTF-8?q?1.=20=E5=A2=9E=E5=8A=A0=E5=BB=B6=E6=97=B6?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E7=A9=BA=E6=8E=A5=E5=8F=A3=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=202.=20opt=20TopViewAnimHelper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/mogo-module-common/build.gradle | 1 + .../module/common/utils/MogoHttpDnsUtil.java | 64 +++++++ .../extensions/net/DelayCheckApiServices.java | 26 --- .../extensions/utils/DelayCheckUtil.java | 142 ---------------- .../extensions/utils/TopViewAnimHelper.java | 4 +- .../delaycheck/DelayCheckApiServices.java | 39 +++++ .../delaycheck/DelayCheckHttpConstant.java | 28 +++ .../main/delaycheck/DelayCheckResponse.java | 29 ++++ .../main/delaycheck/DelayCheckResult.java | 41 +++++ .../delaycheck/DelayCheckUploadRequest.java | 111 ++++++++++++ .../main/delaycheck/DelayCheckUtil.java | 160 ++++++++++++++++++ .../module/main/service/MogoMainService.java | 8 + 12 files changed, 483 insertions(+), 170 deletions(-) create mode 100644 modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/MogoHttpDnsUtil.java delete mode 100644 modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/net/DelayCheckApiServices.java delete mode 100644 modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/DelayCheckUtil.java create mode 100644 modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckApiServices.java create mode 100644 modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckHttpConstant.java create mode 100644 modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckResponse.java create mode 100644 modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckResult.java create mode 100644 modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckUploadRequest.java create mode 100644 modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckUtil.java diff --git a/modules/mogo-module-common/build.gradle b/modules/mogo-module-common/build.gradle index 99e827b866..0ba83c66f7 100644 --- a/modules/mogo-module-common/build.gradle +++ b/modules/mogo-module-common/build.gradle @@ -34,6 +34,7 @@ dependencies { implementation rootProject.ext.dependencies.androidxconstraintlayout implementation rootProject.ext.dependencies.arouter implementation rootProject.ext.dependencies.callchatprovider + implementation "com.mogo.httpdns:httpdns-helper:1.0.1" if (Boolean.valueOf(RELEASE)) { api rootProject.ext.dependencies.mogomap api rootProject.ext.dependencies.mogomapapi diff --git a/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/MogoHttpDnsUtil.java b/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/MogoHttpDnsUtil.java new file mode 100644 index 0000000000..348442bc14 --- /dev/null +++ b/modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/MogoHttpDnsUtil.java @@ -0,0 +1,64 @@ +package com.mogo.module.common.utils; + +import android.content.Context; + +import com.mogo.commons.network.Utils; +import com.mogo.httpdnshelper.sdk.HttpDnsHelper; +import com.mogo.httpdnshelper.sdk.IHttpDnsConfig; +import com.mogo.httpdnshelper.sdk.bean.HttpDnsSimpleLocation; +import com.mogo.map.location.MogoLocation; +import com.mogo.module.common.MogoApisHandler; + +import org.jetbrains.annotations.NotNull; + +/** + * MogoHttpDnsHelper包装类 + * + * @author tongchenfei + */ +public class MogoHttpDnsUtil { + private MogoHttpDnsUtil(){ + + } + private final static MogoHttpDnsUtil INSTANCE = new MogoHttpDnsUtil(); + public static MogoHttpDnsUtil getInstance(){ + return INSTANCE; + } + + public void init(Context context){ + HttpDnsHelper.INSTANCE.init(context, new IHttpDnsConfig() { + @NotNull + @Override + public HttpDnsSimpleLocation getCurrentLocation() { + MogoLocation last = MogoApisHandler.getInstance().getApis().getMapServiceApi().getSingletonLocationClient(context).getLastKnowLocation(); + if(last!=null){ + return new HttpDnsSimpleLocation(last.getCityCode(), last.getLatitude(), last.getLongitude()); + } + return null; + } + + @Override + public boolean showDebugLog() { + return true; + } + + @NotNull + @Override + public String getSn() { + return Utils.getSn(); + } + }); + } + + public String getHttpAddress(){ + return HttpDnsHelper.INSTANCE.getHttpDnsAddress(HttpDnsHelper.HTTP_DNS_TYPE_HTTP); + } + + public String getWsAddress(){ + return HttpDnsHelper.INSTANCE.getHttpDnsAddress(HttpDnsHelper.HTTP_DNS_TYPE_WS); + } + + public void release(){ + HttpDnsHelper.INSTANCE.release(); + } +} diff --git a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/net/DelayCheckApiServices.java b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/net/DelayCheckApiServices.java deleted file mode 100644 index 612df49588..0000000000 --- a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/net/DelayCheckApiServices.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.mogo.module.extensions.net; - -import com.mogo.commons.data.BaseData; - -import java.util.Map; - -import io.reactivex.Observable; -import retrofit2.http.FieldMap; -import retrofit2.http.FormUrlEncoded; -import retrofit2.http.GET; -import retrofit2.http.POST; - -/** - * 时延验证相关接口 - * - * @author tongchenfei - */ -public interface DelayCheckApiServices { - - @GET("/yycp-test-service/net/delay/heartbeat") - Observable emptyInterface(); - - @POST("/yycp-test-service/net/delay/log") - @FormUrlEncoded - Observable uploadDelayCheckData(@FieldMap Map params); -} diff --git a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/DelayCheckUtil.java b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/DelayCheckUtil.java deleted file mode 100644 index f0e68e77ec..0000000000 --- a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/DelayCheckUtil.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.mogo.module.extensions.utils; - -import android.content.Context; -import android.os.Handler; -import android.os.Message; -import android.os.SystemClock; - -import com.mogo.commons.data.BaseData; -import com.mogo.commons.network.SubscribeImpl; -import com.mogo.commons.network.Utils; -import com.mogo.map.location.MogoLocation; -import com.mogo.module.common.MogoApisHandler; -import com.mogo.module.extensions.net.DelayCheckApiServices; -import com.mogo.module.extensions.net.DztHttpConstant; -import com.mogo.utils.NetworkUtils; -import com.mogo.utils.network.RequestOptions; - -import java.util.HashMap; -import java.util.Map; - -import io.reactivex.schedulers.Schedulers; - -/** - * 延时验证工具类 - * - * @author tongchenfei - */ -public class DelayCheckUtil implements Handler.Callback { - - private final Handler handler = new Handler(this); - - private static final int MSG_CHECK_NET_CONNECT_STATUS = 1001; - private static final long FIRST_CHECK_NET_CONNECT_STATUS_DELAY = 10 * 60 * 1000; - private static final long CHECK_NET_CONNECT_STATUS_DELAY = 5000L; - - private static final int MSG_START_DELAY_CHECK = 1002; - private static final long DELAY_CHECK_DELAY = 10 * 60 * 1000; - - private final Context context; - - public DelayCheckUtil(Context context) { - this.context = context; - } - - /** - * 每5s检查一下网络状态,网络状态为连接状态时,开始空接口请求以及后续的参数上报 - */ - public void waitingForCheck() { - handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, FIRST_CHECK_NET_CONNECT_STATUS_DELAY); - } - - private long requestTime, netDelay, requestSystemTime; - - @Override - public boolean handleMessage(Message msg) { - switch (msg.what) { - case MSG_CHECK_NET_CONNECT_STATUS: - if (NetworkUtils.isConnected(context)) { - handler.sendEmptyMessage(MSG_START_DELAY_CHECK); - } else { - handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY); - } - return true; - case MSG_START_DELAY_CHECK: - // 请求空接口 - startEmptyRequest(); - return true; - default: - return false; - } - } - - private void startEmptyRequest() { - requestTime = SystemClock.elapsedRealtime(); - requestSystemTime = System.currentTimeMillis(); - MogoApisHandler.getInstance().getApis().getNetworkApi() - .create(DelayCheckApiServices.class, DztHttpConstant.getBaseUrl()) - .emptyInterface().subscribeOn(Schedulers.io()).observeOn(Schedulers.io()) - .subscribe(new SubscribeImpl(RequestOptions.create(context)) { - @Override - public void onSuccess(BaseData o) { - super.onSuccess(o); - netDelay = SystemClock.elapsedRealtime() - requestTime; - startUpload(); - - } - - @Override - public void onError(Throwable e) { - super.onError(e); - handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY); - } - - @Override - public void onError(String message, int code) { - super.onError(message, code); - handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY); - } - }); - } - - private void startUpload() { - MogoLocation lastLocation = MogoApisHandler.getInstance().getApis().getMapServiceApi().getSingletonLocationClient(context).getLastKnowLocation(); - if (lastLocation == null) { - handler.sendEmptyMessageDelayed(MSG_START_DELAY_CHECK, DELAY_CHECK_DELAY); - return; - } - Map params = new HashMap<>(8); - params.put("sn", Utils.getSn()); - params.put("startTime", requestSystemTime); - params.put("endTime", System.currentTimeMillis()); - params.put("netState", NetworkUtils.netStrengthLevel); - params.put("place", lastLocation.getAddress()); - params.put("cityCode", lastLocation.getCityCode()); - params.put("lat", lastLocation.getLatitude()); - params.put("lon", lastLocation.getLongitude()); - - MogoApisHandler.getInstance().getApis().getNetworkApi() - .create(DelayCheckApiServices.class, DztHttpConstant.getBaseUrl()) - .uploadDelayCheckData(params).observeOn(Schedulers.io()).subscribeOn(Schedulers.io()) - .subscribe(new SubscribeImpl(RequestOptions.create(context)) { - @Override - public void onSuccess(BaseData o) { - super.onSuccess(o); - - handler.sendEmptyMessageDelayed(MSG_START_DELAY_CHECK, DELAY_CHECK_DELAY); - } - - @Override - public void onError(String message, int code) { - super.onError(message, code); - handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY); - } - - @Override - public void onError(Throwable e) { - super.onError(e); - handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY); - } - }); - } -} diff --git a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/TopViewAnimHelper.java b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/TopViewAnimHelper.java index 054bdadf5e..ad8f008f79 100644 --- a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/TopViewAnimHelper.java +++ b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/utils/TopViewAnimHelper.java @@ -292,12 +292,12 @@ public class TopViewAnimHelper { int scene = 0; if (animNavInfoView.isVisible()) { scene = Scene.NAVI_WITH_ROAD_EVENT; - animNavInfoView.animate().translationY(computeNaviMarginTop(child.getHeight())).start(); + animNavInfoView.animate().translationY(computeNaviMarginTop(params.height)).start(); animNavInfoView.exchangeToSmall(true); } else { scene = Scene.AIMLESS_WITH_ROAD_EVENT; } - topContainer.animate().translationY(child.getHeight()).setListener(mainAnimListener).start(); + topContainer.animate().translationY(params.height).setListener(mainAnimListener).start(); Logger.d(TAG, "show top setMapCenterPointByScene: " + scene); MapCenterPointStrategy.setMapCenterPointByScene(mogoMapUIController, scene); } catch (Exception e) { diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckApiServices.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckApiServices.java new file mode 100644 index 0000000000..5a1050edf3 --- /dev/null +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckApiServices.java @@ -0,0 +1,39 @@ +package com.mogo.module.main.delaycheck; + +import com.mogo.commons.data.BaseData; + +import java.util.Map; + +import io.reactivex.Observable; +import okhttp3.RequestBody; +import retrofit2.http.Body; +import retrofit2.http.FieldMap; +import retrofit2.http.FormUrlEncoded; +import retrofit2.http.GET; +import retrofit2.http.Headers; +import retrofit2.http.POST; + +/** + * 时延验证相关接口 + * + * @author tongchenfei + */ +public interface DelayCheckApiServices { + + /** + * 空接口 + * @return 什么都不返回 + */ + @GET("/yycp-test-service/net/delay/heartbeat") + Observable emptyInterface(); + + /** + * 时延上报接口 接口文档如下 + * http://wiki.zhidaohulian.com/pages/viewpage.action?pageId=48967034 + * @param params 相关参数,详见文档 + * @return 相关返回值,详见文档 + */ + @POST("/yycp-test-service/net/delay/log") + @Headers({"Content-type:application/json;charset=UTF-8"}) + Observable uploadDelayCheckData(@Body RequestBody params); +} diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckHttpConstant.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckHttpConstant.java new file mode 100644 index 0000000000..41ebedaf72 --- /dev/null +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckHttpConstant.java @@ -0,0 +1,28 @@ +package com.mogo.module.main.delaycheck; + +import com.mogo.commons.debug.DebugConfig; + +/** + * dzt base url + * + * @author tongchenfei + */ +public class DelayCheckHttpConstant { + public static final String HOST_DEV = "http://dzt-test.zhidaozhixing.com"; + public static final String HOST_TEST = "http://dzt-test.zhidaozhixing.com"; + public static final String HOST_DEMO = "http://dzt-show.zhidaozhixing.com"; + public static final String HOST_PRODUCT = "http://dzt.zhidaozhixing.com"; + + public static String getBaseUrl(){ + switch ( DebugConfig.getNetMode() ) { + case DebugConfig.NET_MODE_DEV: + return HOST_DEV; + case DebugConfig.NET_MODE_QA: + return HOST_TEST; + case DebugConfig.NET_MODE_DEMO: + return HOST_DEMO; + default: + return HOST_PRODUCT; + } + } +} diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckResponse.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckResponse.java new file mode 100644 index 0000000000..e88d95bdbb --- /dev/null +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckResponse.java @@ -0,0 +1,29 @@ +package com.mogo.module.main.delaycheck; + +import com.mogo.commons.data.BaseData; + +/** + * 延迟检测response + * + * @author tongchenfei + */ +public class DelayCheckResponse extends BaseData { + private DelayCheckResult result; + + public DelayCheckResult getResult() { + return result; + } + + public void setResult(DelayCheckResult result) { + this.result = result; + } + + @Override + public String toString() { + return "DelayCheckResponse{" + + "result=" + result + + ", code=" + code + + ", msg='" + msg + '\'' + + '}'; + } +} diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckResult.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckResult.java new file mode 100644 index 0000000000..320407a9be --- /dev/null +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckResult.java @@ -0,0 +1,41 @@ +package com.mogo.module.main.delaycheck; + +/** + * 延迟检查返回结果 + * + * @author tongchenfei + */ +public class DelayCheckResult { + /** + * 是否保持心跳 + */ + private boolean necessary; + /** + * 心跳间隔,单位 s + */ + private int beatSeconds; + + public boolean isNecessary() { + return necessary; + } + + public void setNecessary(boolean necessary) { + this.necessary = necessary; + } + + public int getBeatSeconds() { + return beatSeconds; + } + + public void setBeatSeconds(int beatSeconds) { + this.beatSeconds = beatSeconds; + } + + @Override + public String toString() { + return "DelayCheckResult{" + + "necessary=" + necessary + + ", beatSeconds=" + beatSeconds + + '}'; + } +} diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckUploadRequest.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckUploadRequest.java new file mode 100644 index 0000000000..11d6216d74 --- /dev/null +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckUploadRequest.java @@ -0,0 +1,111 @@ +package com.mogo.module.main.delaycheck; + +/** + * 时延检测上报请求参数 + * + * @author tongchenfei + */ +public class DelayCheckUploadRequest { + private String sn; + private long startTime; + private long endTime; + /** + * 请求时长 + */ + private long burning; + /** + * 信号强度 + */ + private int netState; + private String place; + private String cityCode; + private double lat; + private double lon; + + public String getSn() { + return sn; + } + + public void setSn(String sn) { + this.sn = sn; + } + + public long getStartTime() { + return startTime; + } + + public void setStartTime(long startTime) { + this.startTime = startTime; + } + + public long getEndTime() { + return endTime; + } + + public void setEndTime(long endTime) { + this.endTime = endTime; + } + + public long getBurning() { + return burning; + } + + public void setBurning(long burning) { + this.burning = burning; + } + + public int getNetState() { + return netState; + } + + public void setNetState(int netState) { + this.netState = netState; + } + + public String getPlace() { + return place; + } + + public void setPlace(String place) { + this.place = place; + } + + public String getCityCode() { + return cityCode; + } + + public void setCityCode(String cityCode) { + this.cityCode = cityCode; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + + public double getLon() { + return lon; + } + + public void setLon(double lon) { + this.lon = lon; + } + + @Override + public String toString() { + return "DelayCheckUploadRequest{" + + "sn='" + sn + '\'' + + ", startTime=" + startTime + + ", endTime=" + endTime + + ", burning=" + burning + + ", netState=" + netState + + ", place='" + place + '\'' + + ", cityCode='" + cityCode + '\'' + + ", lat=" + lat + + ", lon=" + lon + + '}'; + } +} diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckUtil.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckUtil.java new file mode 100644 index 0000000000..61292de9d8 --- /dev/null +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/delaycheck/DelayCheckUtil.java @@ -0,0 +1,160 @@ +package com.mogo.module.main.delaycheck; + +import android.content.Context; +import android.os.Handler; +import android.os.Message; +import android.os.SystemClock; + +import com.mogo.commons.data.BaseData; +import com.mogo.commons.network.SubscribeImpl; +import com.mogo.commons.network.Utils; +import com.mogo.map.location.MogoLocation; +import com.mogo.module.common.MogoApisHandler; +import com.mogo.utils.NetworkUtils; +import com.mogo.utils.logger.Logger; +import com.mogo.utils.network.RequestOptions; +import com.mogo.utils.network.utils.GsonUtil; + +import java.util.HashMap; +import java.util.Map; + +import io.reactivex.schedulers.Schedulers; +import okhttp3.MediaType; +import okhttp3.RequestBody; + +/** + * 延时验证工具类 + * + * @author tongchenfei + */ +public class DelayCheckUtil implements Handler.Callback { + private static final String TAG = "DelayCheckUtil"; + private final Handler handler = new Handler(this); + + private static final int MSG_CHECK_NET_CONNECT_STATUS = 1001; + /** + * 首次延时检测时间间隔,暂定10分钟,等待机器稳定后再做打算 + */ + private static final long FIRST_CHECK_NET_CONNECT_STATUS_DELAY = 10 * 60 * 1000; + private static final long CHECK_NET_CONNECT_STATUS_DELAY = 5000L; + + private static final int MSG_START_DELAY_CHECK = 1002; + /** + * 默认检测时间间隔,若服务端正确返回,以服务端返回为主 + */ + private static final long DELAY_CHECK_DELAY = 10 * 60 * 1000; + + private final Context context; + + public DelayCheckUtil(Context context) { + this.context = context; + } + + /** + * 每5s检查一下网络状态,网络状态为连接状态时,开始空接口请求以及后续的参数上报 + */ + public void waitingForCheck() { + Logger.d(TAG, "waitingForCheck==="); + handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, FIRST_CHECK_NET_CONNECT_STATUS_DELAY); + } + + private long requestTime, netDelay, requestStartSystemTime,requestEndSystem; + + @Override + public boolean handleMessage(Message msg) { + switch (msg.what) { + case MSG_CHECK_NET_CONNECT_STATUS: + if (NetworkUtils.isConnected(context)) { + handler.sendEmptyMessage(MSG_START_DELAY_CHECK); + } else { + handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY); + } + return true; + case MSG_START_DELAY_CHECK: + // 请求空接口 + startEmptyRequest(); + return true; + default: + return false; + } + } + + private void startEmptyRequest() { + Logger.d(TAG, "start empty request"); + requestTime = SystemClock.elapsedRealtime(); + requestStartSystemTime = System.currentTimeMillis(); + MogoApisHandler.getInstance().getApis().getNetworkApi() + .create(DelayCheckApiServices.class, DelayCheckHttpConstant.getBaseUrl()) + .emptyInterface().subscribeOn(Schedulers.io()).observeOn(Schedulers.io()) + .subscribe(new SubscribeImpl(RequestOptions.create(context)) { + @Override + public void onSuccess(BaseData o) { + super.onSuccess(o); + requestEndSystem = System.currentTimeMillis(); + netDelay = SystemClock.elapsedRealtime() - requestTime; + startUpload(); + } + + @Override + public void onError(Throwable e) { + super.onError(e); + handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY); + } + + @Override + public void onError(String message, int code) { + super.onError(message, code); + handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY); + } + }); + } + + private void startUpload() { + Logger.d(TAG, "start upload"); + MogoLocation lastLocation = MogoApisHandler.getInstance().getApis().getMapServiceApi().getSingletonLocationClient(context).getLastKnowLocation(); + if (lastLocation == null) { + handler.sendEmptyMessageDelayed(MSG_START_DELAY_CHECK, DELAY_CHECK_DELAY); + return; + } + Logger.d(TAG, "lastLocation: " + lastLocation); + DelayCheckUploadRequest request = new DelayCheckUploadRequest(); + request.setSn(Utils.getSn()); + request.setStartTime(requestStartSystemTime); + request.setEndTime(requestEndSystem); + request.setNetState(NetworkUtils.netStrengthLevel); + request.setPlace(lastLocation.getAddress()); + request.setCityCode(lastLocation.getCityCode()); + request.setLat(lastLocation.getLatitude()); + request.setLon(lastLocation.getLongitude()); + request.setBurning(netDelay); + + RequestBody params = RequestBody.create(MediaType.get("application/json"), GsonUtil.jsonFromObject(request)); + + MogoApisHandler.getInstance().getApis().getNetworkApi() + .create(DelayCheckApiServices.class, DelayCheckHttpConstant.getBaseUrl()) + .uploadDelayCheckData(params).observeOn(Schedulers.io()).subscribeOn(Schedulers.io()) + .subscribe(new SubscribeImpl(RequestOptions.create(context)) { + @Override + public void onSuccess(DelayCheckResponse o) { + super.onSuccess(o); + Logger.d(TAG, "上报时延成功 " + o); + DelayCheckResult result = o.getResult(); + if(result.isNecessary()) { + handler.sendEmptyMessageDelayed(MSG_START_DELAY_CHECK, result.getBeatSeconds() * 1000); + } + } + + @Override + public void onError(String message, int code) { + super.onError(message, code); + handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY); + } + + @Override + public void onError(Throwable e) { + super.onError(e); + handler.sendEmptyMessageDelayed(MSG_CHECK_NET_CONNECT_STATUS, CHECK_NET_CONNECT_STATUS_DELAY); + } + }); + } +} diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/service/MogoMainService.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/service/MogoMainService.java index 149ffad5e7..8651848b93 100644 --- a/modules/mogo-module-main/src/main/java/com/mogo/module/main/service/MogoMainService.java +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/service/MogoMainService.java @@ -12,8 +12,10 @@ import com.mogo.map.location.IMogoLocationClient; import com.mogo.map.location.IMogoLocationListener; import com.mogo.map.location.MogoLocation; import com.mogo.module.common.MogoApisHandler; +import com.mogo.module.common.utils.MogoHttpDnsUtil; import com.mogo.module.main.EventDispatchCenter; import com.mogo.module.main.cards.MogoModulesManager; +import com.mogo.module.main.delaycheck.DelayCheckUtil; import com.mogo.service.IMogoServiceApis; import com.mogo.utils.UiThreadHandler; import com.mogo.utils.logger.Logger; @@ -48,6 +50,11 @@ class MogoMainService extends Service implements IMogoLocationListener { initGpsSimulatorListener(); }, 2_000L ); + // 开启延时检测 + DelayCheckUtil delayCheckUtil = new DelayCheckUtil(this); + delayCheckUtil.waitingForCheck(); + + MogoHttpDnsUtil.getInstance().init(this); } @Nullable @@ -104,5 +111,6 @@ class MogoMainService extends Service implements IMogoLocationListener { mLocationClient = null; } mServiceApis = null; + MogoHttpDnsUtil.getInstance().release(); } } From 6c323174211f49ff2aba04862d484602f91ef70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Thu, 24 Dec 2020 17:20:01 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=BF=98=E5=8E=9F=E4=BA=86=E5=A4=9A?= =?UTF-8?q?=E8=BF=9B=E7=A8=8B=E5=B0=8F=E5=9C=B0=E5=9B=BE=E6=96=B9=E6=A1=88?= =?UTF-8?q?=EF=BC=8C=E5=8E=9F=E5=9B=A0=E6=98=AFLayoutInflater.from(this).c?= =?UTF-8?q?loneInContext(this)=E6=B2=A1=E6=9C=89=E8=B5=B7=E5=88=B0?= =?UTF-8?q?=E4=BD=9C=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mogo/commons/AbsMogoApplication.java | 3 +- .../com/mogo/module/main/MainActivity.java | 2 +- .../src/main/AndroidManifest.xml | 7 + .../module/small/map/SmallMapService.java | 134 ++++++++++++++++++ .../module/small/map/SmallVisionProvider.java | 51 ++----- .../com/mogo/module/v2x/view/RoundLayout.java | 8 ++ 6 files changed, 161 insertions(+), 44 deletions(-) create mode 100644 modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallMapService.java diff --git a/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java b/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java index 907e3007d1..636cf85304 100644 --- a/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java +++ b/foudations/mogo-commons/src/main/java/com/mogo/commons/AbsMogoApplication.java @@ -3,6 +3,7 @@ package com.mogo.commons; import android.app.Application; import android.content.Context; import android.text.TextUtils; +import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -59,7 +60,7 @@ public abstract class AbsMogoApplication extends Application { public void onCreate() { super.onCreate(); // 在设置皮肤布局填充器之前进行克隆一个出来 - mLayoutInflaterNoSkin = LayoutInflater.from(this).cloneInContext(this); + mLayoutInflaterNoSkin = LayoutInflater.from(new ContextThemeWrapper(this, R.style.Theme_AppCompat)).cloneInContext(new ContextThemeWrapper(this, R.style.Theme_AppCompat)); sApp = this; initARouter(); if ( shouldInit() ) { diff --git a/modules/mogo-module-main/src/main/java/com/mogo/module/main/MainActivity.java b/modules/mogo-module-main/src/main/java/com/mogo/module/main/MainActivity.java index 4a439ba53d..e23dc28f2f 100644 --- a/modules/mogo-module-main/src/main/java/com/mogo/module/main/MainActivity.java +++ b/modules/mogo-module-main/src/main/java/com/mogo/module/main/MainActivity.java @@ -83,7 +83,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme @Override protected void beforeSetContentView( Bundle savedInstanceState ) { init(); - //installSkinManager( savedInstanceState ); + installSkinManager( savedInstanceState ); } /** diff --git a/modules/mogo-module-smp/src/main/AndroidManifest.xml b/modules/mogo-module-smp/src/main/AndroidManifest.xml index 32b3a76248..32b078729c 100644 --- a/modules/mogo-module-smp/src/main/AndroidManifest.xml +++ b/modules/mogo-module-smp/src/main/AndroidManifest.xml @@ -1,4 +1,11 @@ + + + + \ No newline at end of file diff --git a/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallMapService.java b/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallMapService.java new file mode 100644 index 0000000000..1b566a3a78 --- /dev/null +++ b/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallMapService.java @@ -0,0 +1,134 @@ +package com.mogo.module.small.map; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.os.RemoteException; +import android.view.Gravity; +import android.view.WindowManager; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.mogo.module.common.entity.MogoSnapshotSetData; +import com.mogo.module.common.machinevision.IMachineVisionInterface; +import com.mogo.module.common.wm.WindowManagerView; +import com.mogo.utils.logger.Logger; + +/** + * @author donghongyu + * @date 12/10/20 1:35 PM + */ +public class SmallMapService extends Service { + private static final String TAG = "MachineVisionMapService"; + private IBinder mBinder; + + private WindowManagerView mWindowManagerView; + private SmallMapDirectionView mSmallMapDirectionView; + + @Override + public void onCreate() { + super.onCreate(); + Logger.d(TAG, "onCreate"); + addSmallMapView(); + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + Logger.d(TAG, "onBind"); + mBinder = new SmallMapServiceBinder(); + return mBinder; + } + + @Override + public void onRebind(Intent intent) { + super.onRebind(intent); + addSmallMapView(); + Logger.d(TAG, "onRebind"); + } + + @Override + public boolean onUnbind(Intent intent) { + Logger.d(TAG, "onUnbind"); + if (mWindowManagerView != null && mWindowManagerView.isShowing()) { + mWindowManagerView.dismiss(); + } + mWindowManagerView = null; + return true; + } + + @Override + public void onDestroy() { + super.onDestroy(); + Logger.d(TAG, "onDestroy"); + if (mWindowManagerView != null) { + mWindowManagerView.dismiss(); + } + } + + /** + * 添加小地图View + */ + private void addSmallMapView() { + Logger.d(TAG, "addSmallMapView"); + + // 初始化小地图控件 + mSmallMapDirectionView = new SmallMapDirectionView(getApplicationContext()); + + mWindowManagerView = new WindowManagerView.Builder(getApplicationContext()) + .contentView(mSmallMapDirectionView) + .size( + WindowManager.LayoutParams.WRAP_CONTENT, + WindowManager.LayoutParams.WRAP_CONTENT + ) + .position( + getResources().getDimensionPixelOffset(R.dimen.module_small_map_view_x), + getResources().getDimensionPixelOffset(R.dimen.module_small_map_view_y) + ) + .gravity(Gravity.TOP | Gravity.LEFT) + .showInWindowManager(); + mWindowManagerView.show(); + } + + + /** + * 小地图与大地图之间进程通讯 + */ + public class SmallMapServiceBinder extends IMachineVisionInterface.Stub { + + @Override + public void linkToDeath(@NonNull DeathRecipient recipient, int flags) { + super.linkToDeath(recipient, flags); + Logger.d(TAG, "linkToDeath"); + + } + + @Override + public boolean unlinkToDeath(@NonNull DeathRecipient recipient, int flags) { + Logger.d(TAG, "unlinkToDeath"); + + return super.unlinkToDeath(recipient, flags); + } + + @Override + public void postData(MogoSnapshotSetData data) throws RemoteException { + Logger.d(TAG, "postData"); + + } + + @Override + public void hideViewIfExist() throws RemoteException { + Logger.d(TAG, "hideViewIfExist"); + + } + + @Override + public void showViewIfExist() throws RemoteException { + Logger.d(TAG, "showViewIfExist"); + + } + + + } +} diff --git a/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallVisionProvider.java b/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallVisionProvider.java index d5449144b5..10fb9139b9 100644 --- a/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallVisionProvider.java +++ b/modules/mogo-module-smp/src/main/java/com/mogo/module/small/map/SmallVisionProvider.java @@ -1,24 +1,22 @@ package com.mogo.module.small.map; import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.util.Log; -import android.view.Gravity; import android.view.View; -import android.view.WindowManager; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import com.alibaba.android.arouter.facade.annotation.Route; +import com.mogo.commons.AbsMogoApplication; import com.mogo.module.common.MogoApisHandler; -import com.mogo.module.common.wm.WindowManagerView; import com.mogo.service.MogoServicePaths; import com.mogo.service.map.IMogoSmallMapProvider; import com.mogo.service.module.ModuleType; import com.mogo.service.statusmanager.IMogoStatusChangedListener; import com.mogo.service.statusmanager.StatusDescriptor; -import com.mogo.utils.logger.Logger; /** * @author donghongyu @@ -28,11 +26,9 @@ import com.mogo.utils.logger.Logger; public class SmallVisionProvider implements IMogoSmallMapProvider, IMogoStatusChangedListener { private final String TAG = "SmallVisionProvider"; + private Intent mSmallMapServiceIntent; private Context mContext; - private WindowManagerView mWindowManagerView; - private SmallMapDirectionView mSmallMapDirectionView; - @Override public Fragment createFragment(Context context, Bundle data) { return null; @@ -80,22 +76,22 @@ public class SmallVisionProvider implements IMogoSmallMapProvider, IMogoStatusCh public void onDestroy() { Log.d(TAG, "小地图模块销毁……"); hidePanel(); - // 释放组件内存 - mSmallMapDirectionView = null; - mWindowManagerView = null; } @Override public void showPanel() { Log.d(TAG, "小地图模块触发展示……"); - addSmallMapView(); + if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) { + mSmallMapServiceIntent = new Intent(mContext, SmallMapService.class); + mContext.startService(mSmallMapServiceIntent); + } } @Override public void hidePanel() { Log.d(TAG, "小地图模块触发隐藏……"); - if (mWindowManagerView != null && mWindowManagerView.isShowing()) { - mWindowManagerView.dismiss(); + if (mSmallMapServiceIntent != null) { + AbsMogoApplication.getApp().stopService(mSmallMapServiceIntent); } } @@ -126,33 +122,4 @@ public class SmallVisionProvider implements IMogoSmallMapProvider, IMogoStatusCh } } } - - - /** - * 添加小地图View - */ - private void addSmallMapView() { - Logger.d(TAG, "addSmallMapView"); - // 初始化小地图控件 - if (mSmallMapDirectionView == null) { - mSmallMapDirectionView = new SmallMapDirectionView(mContext); - } - - if (mWindowManagerView == null) { - mWindowManagerView = new WindowManagerView.Builder(mContext) - .contentView(mSmallMapDirectionView) - .size( - WindowManager.LayoutParams.WRAP_CONTENT, - WindowManager.LayoutParams.WRAP_CONTENT - ) - .position( - mContext.getResources().getDimensionPixelOffset(R.dimen.module_small_map_view_x), - mContext.getResources().getDimensionPixelOffset(R.dimen.module_small_map_view_y) - ) - .gravity(Gravity.TOP | Gravity.LEFT) - .showInWindowManager(); - } - mWindowManagerView.show(); - } - } diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/RoundLayout.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/RoundLayout.java index b0645b5823..a32e369284 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/RoundLayout.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/view/RoundLayout.java @@ -80,6 +80,14 @@ public class RoundLayout extends RelativeLayout implements IMogoSkinCompatSuppor super.draw(canvas); } + @Override + public void setBackgroundResource(int resId) { + super.setBackgroundResource(resId); + if (mBackgroundTintHelper != null) { + mBackgroundTintHelper.onSetBackgroundResource(resId); + } + } + @Override public void applySkin() { if (mBackgroundTintHelper != null) { From bb17572feac076b75524c2af6ce2a15c90e9243d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=AE=87?= Date: Thu, 24 Dec 2020 17:34:20 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=85=B3=E9=97=AD=E4=BA=86=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mogo/module/v2x/alarm/V2XAlarmServer.java | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/alarm/V2XAlarmServer.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/alarm/V2XAlarmServer.java index ef7ce042d4..d42c409a80 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/alarm/V2XAlarmServer.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/alarm/V2XAlarmServer.java @@ -111,19 +111,19 @@ public class V2XAlarmServer { } // 进行提醒 if (!isAlreadyAlert) { - Logger.w(MODULE_NAME, "V2X预警--车辆与事件信息:" + - "\n事件详情ID:" + v2XRoadEventEntity.getNoveltyInfo().getInfoId() + - "\n事件详情:" + GsonUtil.jsonFromObject(v2XRoadEventEntity.getNoveltyInfo()) + - "\n距离:" + v2XRoadEventEntity.getDistance() + "米" + - "\n是否已经提醒:" + isAlreadyAlert + - "\n当前车辆-经度:" + currentLocation.getLongitude() + - "\n当前车辆-经度:" + currentLocation.getLatitude() + - "\n当前车辆-角度:" + currentLocation.getBearing() + - "\n道路事件-经度:" + eventLocation.getLon() + - "\n道路事件-经度:" + eventLocation.getLat() + - "\n道路事件-角度:" + eventLocation.getAngle() + - "\n夹角角度:" + eventAngle + " 度" - ); +// Logger.w(MODULE_NAME, "V2X预警--车辆与事件信息:" + +// "\n事件详情ID:" + v2XRoadEventEntity.getNoveltyInfo().getInfoId() + +// "\n事件详情:" + GsonUtil.jsonFromObject(v2XRoadEventEntity.getNoveltyInfo()) + +// "\n距离:" + v2XRoadEventEntity.getDistance() + "米" + +// "\n是否已经提醒:" + isAlreadyAlert + +// "\n当前车辆-经度:" + currentLocation.getLongitude() + +// "\n当前车辆-经度:" + currentLocation.getLatitude() + +// "\n当前车辆-角度:" + currentLocation.getBearing() + +// "\n道路事件-经度:" + eventLocation.getLon() + +// "\n道路事件-经度:" + eventLocation.getLat() + +// "\n道路事件-角度:" + eventLocation.getAngle() + +// "\n夹角角度:" + eventAngle + " 度" +// ); mAlertRoadEventList.put(v2XRoadEventEntity, TimeUtils.getNowString()); return v2XRoadEventEntity; } @@ -141,13 +141,13 @@ public class V2XAlarmServer { // ); } } else { - Logger.w(MODULE_NAME, - "V2X预警--车头方向与事件方向角度不一致:" + - "\n事件详情:" + v2XRoadEventEntity.getNoveltyInfo().getInfoId() + - "\n车头方向: " + carBearing + - "\n事件方向:" + eventBearing + - "\n角度差值:" + diffAngle - ); +// Logger.w(MODULE_NAME, +// "V2X预警--车头方向与事件方向角度不一致:" + +// "\n事件详情:" + v2XRoadEventEntity.getNoveltyInfo().getInfoId() + +// "\n车头方向: " + carBearing + +// "\n事件方向:" + eventBearing + +// "\n角度差值:" + diffAngle +// ); } } else { // Logger.w(MODULE_NAME, "V2X预警--车辆距离事件距离大于500米了:" + @@ -156,10 +156,10 @@ public class V2XAlarmServer { // ); } } else { - Logger.e(MODULE_NAME, - "V2X预警--道路事件没有角度信息" + - "\n事件详情:" + v2XRoadEventEntity.getNoveltyInfo().getInfoId() - ); +// Logger.e(MODULE_NAME, +// "V2X预警--道路事件没有角度信息" + +// "\n事件详情:" + v2XRoadEventEntity.getNoveltyInfo().getInfoId() +// ); } } } From a96dcf19e095807fde3a67ba93d8de057c77b2df Mon Sep 17 00:00:00 2001 From: tongchenfei Date: Thu, 24 Dec 2020 20:30:54 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B5=84=E6=BA=90http-dn?= =?UTF-8?q?s=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/gradle.xml | 1 + .../java/com/freedom/app2/MainActivity.java | 7 +- .../java/com/mogo/httpdns/HttpDnsConst.java | 4 + .../java/com/mogo/httpdns/IMogoHttpDns.java | 68 +++++++--- foudations/httpdns-mogo/.gitignore | 1 + foudations/httpdns-mogo/build.gradle | 48 +++++++ foudations/httpdns-mogo/consumer-rules.pro | 0 foudations/httpdns-mogo/gradle.properties | 3 + foudations/httpdns-mogo/proguard-rules.pro | 21 +++ .../httpdns/mogo/ExampleInstrumentedTest.java | 26 ++++ .../httpdns-mogo/src/main/AndroidManifest.xml | 5 + .../com/mogo/httpdns/mogo/MogoHttpDns.java | 123 ++++++++++++++++++ .../mogo/httpdns/mogo/ExampleUnitTest.java | 17 +++ .../mogo/httpdns/tencent/TencentHttpDns.java | 31 ++++- .../base/websocket/WebSocketConstant.java | 5 +- .../base/websocket/WebSocketDnsManager.java | 11 +- modules/mogo-module-common/build.gradle | 1 - .../module/common/utils/MogoHttpDnsUtil.java | 64 --------- .../module/main/service/MogoMainService.java | 4 - settings.gradle | 1 + 20 files changed, 338 insertions(+), 103 deletions(-) create mode 100644 foudations/httpdns-mogo/.gitignore create mode 100644 foudations/httpdns-mogo/build.gradle create mode 100644 foudations/httpdns-mogo/consumer-rules.pro create mode 100644 foudations/httpdns-mogo/gradle.properties create mode 100644 foudations/httpdns-mogo/proguard-rules.pro create mode 100644 foudations/httpdns-mogo/src/androidTest/java/com/mogo/httpdns/mogo/ExampleInstrumentedTest.java create mode 100644 foudations/httpdns-mogo/src/main/AndroidManifest.xml create mode 100644 foudations/httpdns-mogo/src/main/java/com/mogo/httpdns/mogo/MogoHttpDns.java create mode 100644 foudations/httpdns-mogo/src/test/java/com/mogo/httpdns/mogo/ExampleUnitTest.java delete mode 100644 modules/mogo-module-common/src/main/java/com/mogo/module/common/utils/MogoHttpDnsUtil.java diff --git a/.idea/gradle.xml b/.idea/gradle.xml index cfc605c98e..8efbfa420e 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -16,6 +16,7 @@