From d00755556008cec67fc1b8f687773df7ef31515d Mon Sep 17 00:00:00 2001 From: liujing Date: Thu, 21 Jan 2021 17:33:21 +0800 Subject: [PATCH] =?UTF-8?q?[add]=20SnapshotUploadInTime=20=E7=B1=BB?= =?UTF-8?q?=E8=A1=A5=E5=85=A8=E7=BC=96=E8=AF=91=E9=80=9A=E8=BF=87,?= =?UTF-8?q?=E7=BC=BA=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/mogo-realtime/build.gradle | 12 ++- .../src/main/AndroidManifest.xml | 4 +- .../realtime/Imp/RealTimeProviderImp.java | 31 ++++++ .../RealTimeApisHandler.java | 2 +- .../RealTimeProvider.java} | 10 +- .../Interface/RealTimeServiceApis.java | 11 ++ .../InterfaceManager/RealTimeServiceApis.java | 15 --- .../SimpleLocationCorrectStrategy.java | 11 +- .../constant/SnapshotUploadInTime.java | 5 +- .../realtime/entity/CloudLocationInfo.java | 5 +- .../realtime/location/MogoRTKLocation.java | 18 ++-- .../com/mogo/realtime/util/MogoLatLng.java | 101 ++++++++++++++++++ 12 files changed, 182 insertions(+), 43 deletions(-) create mode 100644 modules/mogo-realtime/src/main/java/com/mogo/realtime/Imp/RealTimeProviderImp.java rename modules/mogo-realtime/src/main/java/com/mogo/realtime/{InterfaceManager => Interface}/RealTimeApisHandler.java (94%) rename modules/mogo-realtime/src/main/java/com/mogo/realtime/{InterfaceManager/RecognizedResultProvider.java => Interface/RealTimeProvider.java} (61%) create mode 100644 modules/mogo-realtime/src/main/java/com/mogo/realtime/Interface/RealTimeServiceApis.java delete mode 100644 modules/mogo-realtime/src/main/java/com/mogo/realtime/InterfaceManager/RealTimeServiceApis.java rename modules/mogo-realtime/src/main/java/com/mogo/realtime/{util => constant}/SimpleLocationCorrectStrategy.java (94%) create mode 100644 modules/mogo-realtime/src/main/java/com/mogo/realtime/util/MogoLatLng.java diff --git a/modules/mogo-realtime/build.gradle b/modules/mogo-realtime/build.gradle index deb46de..5c42fa5 100644 --- a/modules/mogo-realtime/build.gradle +++ b/modules/mogo-realtime/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 30 - buildToolsVersion "30.0.3" + compileSdkVersion rootProject.ext.android.compileSdkVersion defaultConfig { - minSdkVersion 16 - targetSdkVersion 30 + minSdkVersion rootProject.ext.android.minSdkVersion + targetSdkVersion rootProject.ext.android.targetSdkVersion + versionCode 1 versionName "1.0" @@ -20,6 +20,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies { diff --git a/modules/mogo-realtime/src/main/AndroidManifest.xml b/modules/mogo-realtime/src/main/AndroidManifest.xml index c387c4e..c6968da 100644 --- a/modules/mogo-realtime/src/main/AndroidManifest.xml +++ b/modules/mogo-realtime/src/main/AndroidManifest.xml @@ -1,5 +1,7 @@ + - / + \ No newline at end of file diff --git a/modules/mogo-realtime/src/main/java/com/mogo/realtime/Imp/RealTimeProviderImp.java b/modules/mogo-realtime/src/main/java/com/mogo/realtime/Imp/RealTimeProviderImp.java new file mode 100644 index 0000000..a089e22 --- /dev/null +++ b/modules/mogo-realtime/src/main/java/com/mogo/realtime/Imp/RealTimeProviderImp.java @@ -0,0 +1,31 @@ +package com.mogo.realtime.Imp; + +import android.content.Context; + +import com.mogo.realtime.Interface.RealTimeProvider; +import com.mogo.realtime.entity.ADASRecognizedResult; +import com.mogo.realtime.location.MogoRTKLocation; + +import java.util.List; + +/** + * @author liujing + * @description 描述 + * @since: 2021/1/21 + */ +class RealTimeProviderImp implements RealTimeProvider { + @Override + public List getLastADASRecognizedResult() { + return null; + } + + @Override + public void init(Context context) { + MogoRTKLocation.getInstance().init(); + } + + @Override + public float getDistanceBetweenTwoPoints() { + return 0; + } +} diff --git a/modules/mogo-realtime/src/main/java/com/mogo/realtime/InterfaceManager/RealTimeApisHandler.java b/modules/mogo-realtime/src/main/java/com/mogo/realtime/Interface/RealTimeApisHandler.java similarity index 94% rename from modules/mogo-realtime/src/main/java/com/mogo/realtime/InterfaceManager/RealTimeApisHandler.java rename to modules/mogo-realtime/src/main/java/com/mogo/realtime/Interface/RealTimeApisHandler.java index d23d0f8..46acb72 100644 --- a/modules/mogo-realtime/src/main/java/com/mogo/realtime/InterfaceManager/RealTimeApisHandler.java +++ b/modules/mogo-realtime/src/main/java/com/mogo/realtime/Interface/RealTimeApisHandler.java @@ -1,4 +1,4 @@ -package com.mogo.realtime.InterfaceManager; +package com.mogo.realtime.Interface; /** * @author liujing diff --git a/modules/mogo-realtime/src/main/java/com/mogo/realtime/InterfaceManager/RecognizedResultProvider.java b/modules/mogo-realtime/src/main/java/com/mogo/realtime/Interface/RealTimeProvider.java similarity index 61% rename from modules/mogo-realtime/src/main/java/com/mogo/realtime/InterfaceManager/RecognizedResultProvider.java rename to modules/mogo-realtime/src/main/java/com/mogo/realtime/Interface/RealTimeProvider.java index e65657e..69ca4ca 100644 --- a/modules/mogo-realtime/src/main/java/com/mogo/realtime/InterfaceManager/RecognizedResultProvider.java +++ b/modules/mogo-realtime/src/main/java/com/mogo/realtime/Interface/RealTimeProvider.java @@ -1,4 +1,6 @@ -package com.mogo.realtime.InterfaceManager; +package com.mogo.realtime.Interface; + +import android.content.Context; import com.mogo.realtime.entity.ADASRecognizedResult; @@ -9,11 +11,15 @@ import java.util.List; * @description 描述 * @since: 2021/1/21 */ -public interface RecognizedResultProvider { +public interface RealTimeProvider { /** * 获取 adas 识别列表 * * @return */ List getLastADASRecognizedResult(); + + void init(Context context); + + float getDistanceBetweenTwoPoints(); } diff --git a/modules/mogo-realtime/src/main/java/com/mogo/realtime/Interface/RealTimeServiceApis.java b/modules/mogo-realtime/src/main/java/com/mogo/realtime/Interface/RealTimeServiceApis.java new file mode 100644 index 0000000..eec2e5e --- /dev/null +++ b/modules/mogo-realtime/src/main/java/com/mogo/realtime/Interface/RealTimeServiceApis.java @@ -0,0 +1,11 @@ +package com.mogo.realtime.Interface; + +/** + * @author liujing + * @description 描述 + * @since: 2021/1/21 + */ +public interface RealTimeServiceApis { + RealTimeProvider getRecognizedResultManager(); + +} diff --git a/modules/mogo-realtime/src/main/java/com/mogo/realtime/InterfaceManager/RealTimeServiceApis.java b/modules/mogo-realtime/src/main/java/com/mogo/realtime/InterfaceManager/RealTimeServiceApis.java deleted file mode 100644 index b852e33..0000000 --- a/modules/mogo-realtime/src/main/java/com/mogo/realtime/InterfaceManager/RealTimeServiceApis.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.mogo.realtime.InterfaceManager; - -import com.mogo.realtime.entity.ADASRecognizedResult; - -import java.util.List; - -/** - * @author liujing - * @description 描述 - * @since: 2021/1/21 - */ -public interface RealTimeServiceApis { - RecognizedResultProvider getRecognizedResultManager(); - -} diff --git a/modules/mogo-realtime/src/main/java/com/mogo/realtime/util/SimpleLocationCorrectStrategy.java b/modules/mogo-realtime/src/main/java/com/mogo/realtime/constant/SimpleLocationCorrectStrategy.java similarity index 94% rename from modules/mogo-realtime/src/main/java/com/mogo/realtime/util/SimpleLocationCorrectStrategy.java rename to modules/mogo-realtime/src/main/java/com/mogo/realtime/constant/SimpleLocationCorrectStrategy.java index d1d3795..426f119 100644 --- a/modules/mogo-realtime/src/main/java/com/mogo/realtime/util/SimpleLocationCorrectStrategy.java +++ b/modules/mogo-realtime/src/main/java/com/mogo/realtime/constant/SimpleLocationCorrectStrategy.java @@ -1,11 +1,10 @@ -package com.mogo.realtime.util; +package com.mogo.realtime.constant; import android.os.SystemClock; -import com.mogo.map.MogoLatLng; -import com.mogo.module.common.MogoApisHandler; -import com.mogo.module.common.entity.CloudLocationInfo; +import com.mogo.realtime.Interface.RealTimeApisHandler; import com.mogo.realtime.entity.CloudLocationInfo; +import com.mogo.realtime.util.MogoLatLng; import com.mogo.utils.logger.Logger; import java.util.ArrayList; @@ -62,7 +61,7 @@ public class SimpleLocationCorrectStrategy { try { float targetDistance = (float) (lastLocation.getSpeed() * (SystemClock.elapsedRealtime() - anchorTime) / 1000) + TARGET_DISTANCE_DEVIATION; - float distance = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().calculateLineDistance(LocationParseUtil.cloudLocationToMogoLatLng(lastLocation), LocationParseUtil.cloudLocationToMogoLatLng(info)); + float distance = RealTimeApisHandler.getInstance().getApis().getRecognizedResultManager().getDistanceBetweenTwoPoints(); Logger.d(TAG, "准备计算{ lastInfo: " + lastLocation.print() + " info: " + info.print() + " targetDistance: " + targetDistance + " distance : " + distance + "}"); if (distance <= targetDistance) { @@ -122,7 +121,7 @@ public class SimpleLocationCorrectStrategy { try { float targetDistance = (float) (lastLocation.getSpeed() * (SystemClock.elapsedRealtime() - anchorTime) / 1000) + TARGET_DISTANCE_DEVIATION; - float distance = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().calculateLineDistance(LocationParseUtil.cloudLocationToMogoLatLng(lastLocation), LocationParseUtil.cloudLocationToMogoLatLng(info)); + float distance = RealTimeApisHandler.getInstance().getApis().getRecognizedResultManager().getDistanceBetweenTwoPoints(); Logger.d(TAG, "异常定位点\n准备计算{ lastInfo: " + lastLocation.print() + " info: " + info.print() + " targetDistance: " + targetDistance + " distance : " + distance + "}"); // 按照上一个点的方向和速度,计算下一个点的位置,下一个点除坐标点外,其余数据与上一个点相同 diff --git a/modules/mogo-realtime/src/main/java/com/mogo/realtime/constant/SnapshotUploadInTime.java b/modules/mogo-realtime/src/main/java/com/mogo/realtime/constant/SnapshotUploadInTime.java index b2ea607..9eeaa58 100644 --- a/modules/mogo-realtime/src/main/java/com/mogo/realtime/constant/SnapshotUploadInTime.java +++ b/modules/mogo-realtime/src/main/java/com/mogo/realtime/constant/SnapshotUploadInTime.java @@ -4,18 +4,15 @@ import android.content.Context; import android.util.Log; import com.mogo.cloud.passport.MoGoAiCloudClient; -import com.mogo.realtime.InterfaceManager.RealTimeApisHandler; -import com.mogo.realtime.InterfaceManager.RealTimeServiceApis; +import com.mogo.realtime.Interface.RealTimeApisHandler; import com.mogo.realtime.entity.ADASRecognizedResult; import com.mogo.realtime.entity.CloudLocationInfo; import com.mogo.realtime.location.LocationResult; import com.mogo.realtime.location.MogoRTKLocation; import com.mogo.realtime.util.MortonCode; -import com.mogo.realtime.util.SimpleLocationCorrectStrategy; import com.mogo.realtime.websocket.OnePerSecondSendContent; import java.util.List; -import java.util.logging.Logger; /** * @author congtaowang diff --git a/modules/mogo-realtime/src/main/java/com/mogo/realtime/entity/CloudLocationInfo.java b/modules/mogo-realtime/src/main/java/com/mogo/realtime/entity/CloudLocationInfo.java index ea09ba1..e9b665e 100644 --- a/modules/mogo-realtime/src/main/java/com/mogo/realtime/entity/CloudLocationInfo.java +++ b/modules/mogo-realtime/src/main/java/com/mogo/realtime/entity/CloudLocationInfo.java @@ -1,9 +1,11 @@ package com.mogo.realtime.entity; +import android.os.Build; import android.os.Parcel; import android.os.Parcelable; +import androidx.annotation.RequiresApi; -import com.mogo.utils.CoordinateUtils; +import com.mogo.cloud.commons.utils.CoordinateUtils; import java.util.Objects; @@ -167,6 +169,7 @@ public class CloudLocationInfo implements Parcelable { Double.compare( that.lon, lon ) == 0; } + @RequiresApi(api = Build.VERSION_CODES.KITKAT) @Override public int hashCode() { return Objects.hash( lat, lon ); diff --git a/modules/mogo-realtime/src/main/java/com/mogo/realtime/location/MogoRTKLocation.java b/modules/mogo-realtime/src/main/java/com/mogo/realtime/location/MogoRTKLocation.java index 68bcf03..d515844 100644 --- a/modules/mogo-realtime/src/main/java/com/mogo/realtime/location/MogoRTKLocation.java +++ b/modules/mogo-realtime/src/main/java/com/mogo/realtime/location/MogoRTKLocation.java @@ -12,11 +12,13 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; +import com.mogo.cloud.passport.MoGoAiCloudClient; import com.mogo.realtime.entity.CloudLocationInfo; +import com.mogo.utils.WorkThreadHandler; +import com.mogo.utils.logger.Logger; import java.util.ArrayList; import java.util.List; -import java.util.logging.Logger; public class MogoRTKLocation { @@ -38,7 +40,7 @@ public class MogoRTKLocation { } private MogoRTKLocation() { - mHandler = new Handler(WorkThreadHandler.newInstance( TAG ).getLooper() ) { + mHandler = new Handler(WorkThreadHandler.newInstance(TAG).getLooper()) { @Override public void handleMessage(Message msg) { super.handleMessage(msg); @@ -51,7 +53,7 @@ public class MogoRTKLocation { } }; mHandler.sendEmptyMessage(MSG_DATA_CHANGED); - Logger.d(TAG,"构造方法开始发送消息"); + Logger.d(TAG, "构造方法开始发送消息"); } public interface RTKLocationListener { @@ -73,12 +75,12 @@ public class MogoRTKLocation { rtkLocationListener = locationListener; } - public void unregisterRTKLocationListener(){ + public void unregisterRTKLocationListener() { rtkLocationListener = null; } public void init() { - locationManager = (LocationManager) AbsMogoApplication.getApp().getApplicationContext().getSystemService(Context.LOCATION_SERVICE); + locationManager = (LocationManager) MoGoAiCloudClient.getInstance().getContext().getSystemService(Context.LOCATION_SERVICE); String provider = locationManager.getBestProvider(getCriteria(), true); Logger.d(TAG, "init provider : " + provider); if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { @@ -96,9 +98,6 @@ public class MogoRTKLocation { Logger.d(TAG, "RTK LocationManager Provider GPS_PROVIDER unable"); } - // 注册修改上报间隔的广播, 临时使用,后面可直接干掉,发送广播的地方在EntranceFragment - IntentFilter filter = new IntentFilter("com.mogo.launcher.action.FIX_UPLOAT_DELAY"); - AbsMogoApplication.getApp().registerReceiver(fixUploadDelayReceiver, filter); } private Criteria getCriteria() { @@ -159,7 +158,7 @@ public class MogoRTKLocation { private FixUploadDelayReceiver fixUploadDelayReceiver = new FixUploadDelayReceiver(); - private class FixUploadDelayReceiver extends BroadcastReceiver{ + private class FixUploadDelayReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { uploadDelay = intent.getIntExtra("fixTime", 0); @@ -168,6 +167,7 @@ public class MogoRTKLocation { /** * 默认保持{@link #uploadDelay}间隔进行位置上报,如遇服务端控制,进行上报间隔修改 + * * @param delay 上报间隔 */ public void resetUploadDelay(long delay) { diff --git a/modules/mogo-realtime/src/main/java/com/mogo/realtime/util/MogoLatLng.java b/modules/mogo-realtime/src/main/java/com/mogo/realtime/util/MogoLatLng.java new file mode 100644 index 0000000..5b96069 --- /dev/null +++ b/modules/mogo-realtime/src/main/java/com/mogo/realtime/util/MogoLatLng.java @@ -0,0 +1,101 @@ +package com.mogo.realtime.util; + +import android.os.Build; +import android.os.Parcel; +import android.os.Parcelable; + +import androidx.annotation.RequiresApi; + +import java.util.Objects; + +/** + * @author congtaowang + * @since 2019-12-18 + *

+ * 经纬度 + */ +public class MogoLatLng implements Parcelable { + + public final double lat; + @Deprecated + public final double lng; + public final double lon; + + public MogoLatLng(double lat, double lon ) { + this.lat = lat; + this.lng = lon; + this.lon = lon; + } + + public double getLat() { + return lat; + } + + /** + * Deprecated, use {@link #getLon()} instead. + * + * @return + */ + @Deprecated + public double getLng() { + return lng; + } + + public double getLon() { + return lon; + } + + + @Override + public boolean equals( Object o ) { + if ( this == o ) return true; + if ( o == null || getClass() != o.getClass() ) return false; + MogoLatLng latLng = ( MogoLatLng ) o; + return Double.compare( latLng.lat, lat ) == 0 && + Double.compare( latLng.lon, lon ) == 0; + } + + @RequiresApi(api = Build.VERSION_CODES.KITKAT) + @Override + public int hashCode() { + return Objects.hash( lat, lng, lon ); + } + + @Override + public String toString() { + return "MogoLatLng{" + + "lat=" + lat + + ", lon=" + lon + + '}'; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel( Parcel dest, int flags ) { + dest.writeDouble( this.lat ); + dest.writeDouble( this.lng ); + dest.writeDouble( this.lon ); + } + + protected MogoLatLng(Parcel in ) { + this.lat = in.readDouble(); + this.lng = in.readDouble(); + this.lon = in.readDouble(); + } + + public static final Creator< MogoLatLng > CREATOR = new Creator< MogoLatLng >() { + @Override + public MogoLatLng createFromParcel( Parcel source ) { + return new MogoLatLng( source ); + } + + @Override + public MogoLatLng[] newArray( int size ) { + return new MogoLatLng[size]; + } + }; +}