From 444b7a4c68a4e2251dabfd93dace3e9ad0eebeba Mon Sep 17 00:00:00 2001 From: zhongchao Date: Wed, 17 Nov 2021 17:14:22 +0800 Subject: [PATCH] fix bug of location to upload socket server --- .idea/misc.xml | 2 + app/build.gradle | 2 + app/src/main/AndroidManifest.xml | 18 +- .../java/com/mogo/cloud/LocationActivity.java | 69 +++++ .../java/com/mogo/cloud/MainActivity.java | 7 + .../java/com/mogo/cloud/MoGoApplication.java | 1 + .../location/MogoLocationInfoServices.java | 59 ++++ .../cloud/location/MogoLocationSource.java | 126 +++++++++ app/src/main/res/layout/activity_location.xml | 23 ++ app/src/main/res/layout/activity_main.xml | 6 + foudations/mogo-location/build.gradle | 8 +- .../src/main/AndroidManifest.xml | 5 + .../location/third/ThirdLocationManager.java | 9 +- .../location/third/core/AbstractLocation.java | 65 +++++ .../cloud/location/third/core/ILocation.java | 66 +++++ .../location/third/core/LocUploadConfig.java | 47 ++++ .../location/third/core/LocUploadManager.java | 44 +++ .../cloud/location/third/core/Location.java | 262 ++++++++++++++++++ .../third/core/LocationDelegateManager.java | 61 ++++ .../third/core/LocationServiceProvider.java | 4 + .../third/service/SocketRequestUtil.java | 95 +++++++ .../third/service/UploadDataService.java | 139 ++++++++++ gradle.properties | 20 +- 23 files changed, 1113 insertions(+), 25 deletions(-) create mode 100644 app/src/main/java/com/mogo/cloud/LocationActivity.java create mode 100644 app/src/main/java/com/mogo/cloud/location/MogoLocationInfoServices.java create mode 100644 app/src/main/java/com/mogo/cloud/location/MogoLocationSource.java create mode 100644 app/src/main/res/layout/activity_location.xml create mode 100644 foudations/mogo-location/src/main/java/com/mogo/cloud/location/third/core/AbstractLocation.java create mode 100644 foudations/mogo-location/src/main/java/com/mogo/cloud/location/third/core/ILocation.java create mode 100644 foudations/mogo-location/src/main/java/com/mogo/cloud/location/third/core/LocUploadConfig.java create mode 100644 foudations/mogo-location/src/main/java/com/mogo/cloud/location/third/core/LocUploadManager.java create mode 100644 foudations/mogo-location/src/main/java/com/mogo/cloud/location/third/core/Location.java create mode 100644 foudations/mogo-location/src/main/java/com/mogo/cloud/location/third/core/LocationDelegateManager.java create mode 100644 foudations/mogo-location/src/main/java/com/mogo/cloud/location/third/core/LocationServiceProvider.java create mode 100644 foudations/mogo-location/src/main/java/com/mogo/cloud/location/third/service/SocketRequestUtil.java create mode 100644 foudations/mogo-location/src/main/java/com/mogo/cloud/location/third/service/UploadDataService.java diff --git a/.idea/misc.xml b/.idea/misc.xml index daa7ca6..610ea89 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,7 +13,9 @@ + + diff --git a/app/build.gradle b/app/build.gradle index 0166977..de84c76 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,10 +57,12 @@ dependencies { implementation 'com.zhidao.carmanager:common:1.0.25@aar' if (Boolean.valueOf(RELEASE)) { + implementation "com.mogo.cloud:location:${MOGO_LOCATION_VERSION}" implementation "com.mogo.cloud:tanlu:${MOGO_TANLU_VERSION}" implementation "com.mogo.cloud:realtime:${MOGO_REALTIME_VERSION}" implementation "com.mogo.cloud:trafficlive:${MOGO_TRAFFICLIVE_VERSION}" } else { + implementation project(":foudations:mogo-location") implementation project(":modules:mogo-tanlu") implementation project(":modules:mogo-realtime") implementation project(":modules:mogo-trafficlive") diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c11ed4a..1d35262 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -60,19 +60,23 @@ android:name=".RealTimeActivity" android:label="实时数据测试" android:launchMode="singleTask" /> + - + --> \ No newline at end of file diff --git a/app/src/main/java/com/mogo/cloud/LocationActivity.java b/app/src/main/java/com/mogo/cloud/LocationActivity.java new file mode 100644 index 0000000..b4476c0 --- /dev/null +++ b/app/src/main/java/com/mogo/cloud/LocationActivity.java @@ -0,0 +1,69 @@ +package com.mogo.cloud; + +import android.os.Bundle; +import android.widget.Button; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +import com.mogo.cloud.location.LocationManager; +import com.mogo.cloud.location.MogoLocationInfoServices; +import com.mogo.cloud.passport.MoGoAiCloudClientConfig; +import com.mogo.cloud.tanlu.bean.location.MogoLocation; +import com.mogo.realtime.socket.SocketHandler; + +/** + * @author arrow + * @description 描述 + * @since: 2021/1/21 + */ +public class LocationActivity extends AppCompatActivity { + + private static final String TAG = "LocationActivity"; + + private Button snapshotLocStart; + private Button snapshotLocStop; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_location); + MogoLocationInfoServices.getInstance().init(this); + SocketHandler.getInstance().initSocket(this, MoGoAiCloudClientConfig.getInstance().getServiceAppId()); + + MogoLocation mogoLocation = new MogoLocation(); + mogoLocation.setAccuracy(0.0f); + mogoLocation.setAdCode("110113"); + mogoLocation.setCityCode("010"); + mogoLocation.setAddress("北京测试"); + mogoLocation.setAltitude(20); + mogoLocation.setSpeed(20.0f); + mogoLocation.setLocationDetail("北京东城环球贸易中心"); + mogoLocation.setBearing(185.8831f); + mogoLocation.setAltitude(0.0); + mogoLocation.setLatitude(40.201138738452414); + mogoLocation.setLongitude(116.74181952698365); + mogoLocation.setLocType(0); + mogoLocation.setGpsAccuracyStatus(0); + mogoLocation.setProvider("AGPS"); + + snapshotLocStart = findViewById(R.id.snapshotLocStart); + snapshotLocStart.setOnClickListener(view -> { + MogoLocationInfoServices.getInstance().start(); + MogoLocationInfoServices.getInstance().provideLocation(mogoLocation); + }); + + snapshotLocStop = findViewById(R.id.snapshotLocStop); + snapshotLocStop.setOnClickListener(view -> { + SocketHandler.getInstance().stop(); + MogoLocationInfoServices.getInstance().stop(); + }); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + SocketHandler.getInstance().stop(); + MogoLocationInfoServices.getInstance().stop(); + } +} diff --git a/app/src/main/java/com/mogo/cloud/MainActivity.java b/app/src/main/java/com/mogo/cloud/MainActivity.java index f4d6504..4b0882f 100644 --- a/app/src/main/java/com/mogo/cloud/MainActivity.java +++ b/app/src/main/java/com/mogo/cloud/MainActivity.java @@ -25,6 +25,7 @@ public class MainActivity extends AppCompatActivity { private Button btnJumpConfigInfo; private Button btnJumpNetWorkPort; private Button btnJumpRealTime; + private Button btnJumpLocation; private Button btnJumpRoadCondition; private Button btnJumpLivePlayAndPush; private Button btnJumpLivePush; @@ -65,6 +66,12 @@ public class MainActivity extends AppCompatActivity { startActivity(intent); }); + btnJumpLocation = findViewById(R.id.btnJumpLocation); + btnJumpLocation.setOnClickListener(v -> { + Intent intent = new Intent(MainActivity.this, LocationActivity.class); + startActivity(intent); + }); + btnJumpRoadCondition = findViewById(R.id.btnJumpRoadcondition); btnJumpRoadCondition.setOnClickListener(v -> { Intent intent = new Intent(MainActivity.this, RoadConditionActivity.class); diff --git a/app/src/main/java/com/mogo/cloud/MoGoApplication.java b/app/src/main/java/com/mogo/cloud/MoGoApplication.java index 2bf9eb0..dbf6bd7 100644 --- a/app/src/main/java/com/mogo/cloud/MoGoApplication.java +++ b/app/src/main/java/com/mogo/cloud/MoGoApplication.java @@ -76,6 +76,7 @@ public class MoGoApplication extends MultiDexApplication { } }); + clientConfig.setUseOriginSocket(true); // 初始化SDK,可以设置状态回调来监听 MoGoAiCloudClient.getInstance().init(this, clientConfig); } diff --git a/app/src/main/java/com/mogo/cloud/location/MogoLocationInfoServices.java b/app/src/main/java/com/mogo/cloud/location/MogoLocationInfoServices.java new file mode 100644 index 0000000..6d0e39f --- /dev/null +++ b/app/src/main/java/com/mogo/cloud/location/MogoLocationInfoServices.java @@ -0,0 +1,59 @@ +package com.mogo.cloud.location; + +import android.content.Context; + +import androidx.annotation.Keep; + +import com.mogo.cloud.tanlu.bean.location.MogoLocation; +import com.mogo.cloud.utils.logger.Logger; + +@Keep +public class MogoLocationInfoServices { + + private static final String TAG = "MogoLocationInfoServices-sdk"; + + private static volatile MogoLocationInfoServices sInstance; + private MogoLocation mLocation; + + private MogoLocationInfoServices() { + } + + @Keep + public static MogoLocationInfoServices getInstance() { + if (sInstance == null) { + synchronized (MogoLocationInfoServices.class) { + if (sInstance == null) { + sInstance = new MogoLocationInfoServices(); + } + } + } + return sInstance; + } + + public synchronized void release() { + sInstance = null; + } + + public void provideLocation(MogoLocation location) { + mLocation = location; + } + + public MogoLocation getLocation() { + return mLocation; + } + + public void start() { + LocationManager.getInstance().start(); + Logger.d(TAG, "sdk - start"); + } + + public void stop() { + LocationManager.getInstance().stop(); + Logger.d(TAG, "sdk - stop"); + } + + public void init(Context context) { + LocationManager.getInstance().init(context); + Logger.d(TAG, "sdk - init"); + } +} diff --git a/app/src/main/java/com/mogo/cloud/location/MogoLocationSource.java b/app/src/main/java/com/mogo/cloud/location/MogoLocationSource.java new file mode 100644 index 0000000..d631466 --- /dev/null +++ b/app/src/main/java/com/mogo/cloud/location/MogoLocationSource.java @@ -0,0 +1,126 @@ +package com.mogo.cloud.location; + +import com.elegant.spi.annotations.Service; +import com.mogo.cloud.location.third.core.LocationServiceProvider; + +@Service(value = LocationServiceProvider.class) +public class MogoLocationSource extends LocationServiceProvider { + + @Override + public float getBearing() { + if (MogoLocationInfoServices.getInstance().getLocation() != null) { + return MogoLocationInfoServices.getInstance().getLocation().getBearing(); + } + return 0; + } + + @Override + public float getAccuracy() { + if (MogoLocationInfoServices.getInstance().getLocation() != null) { + return MogoLocationInfoServices.getInstance().getLocation().getAccuracy(); + } + return 0; + } + + @Override + public String getProvider() { + if (MogoLocationInfoServices.getInstance().getLocation() != null) { + return MogoLocationInfoServices.getInstance().getLocation().getProvider(); + } + return null; + } + + @Override + public float getSpeed() { + if (MogoLocationInfoServices.getInstance().getLocation() != null) { + return MogoLocationInfoServices.getInstance().getLocation().getSpeed(); + } + return 0; + } + + @Override + public double getAltitude() { + if (MogoLocationInfoServices.getInstance().getLocation() != null) { + return MogoLocationInfoServices.getInstance().getLocation().getAltitude(); + } + return 0; + } + + @Override + public String getAdCode() { + if (MogoLocationInfoServices.getInstance().getLocation() != null) { + return MogoLocationInfoServices.getInstance().getLocation().getAdCode(); + } + return null; + } + + @Override + public int getLocType() { + if (MogoLocationInfoServices.getInstance().getLocation() != null) { + return MogoLocationInfoServices.getInstance().getLocation().getLocType(); + } + return 0; + } + + @Override + public double getLatitude() { + if (MogoLocationInfoServices.getInstance().getLocation() != null) { + return MogoLocationInfoServices.getInstance().getLocation().getLatitude(); + } + return 0; + } + + @Override + public double getLongitude() { + if (MogoLocationInfoServices.getInstance().getLocation() != null) { + return MogoLocationInfoServices.getInstance().getLocation().getLongitude(); + } + return 0; + } + + @Override + public long getTime() { + if (MogoLocationInfoServices.getInstance().getLocation() != null) { + return MogoLocationInfoServices.getInstance().getLocation().getTime(); + } + return 0; + } + + @Override + public String getCityCode() { + if (MogoLocationInfoServices.getInstance().getLocation() != null) { + return MogoLocationInfoServices.getInstance().getLocation().getCityCode(); + } + return null; + } + + @Override + public String getCityName() { + if (MogoLocationInfoServices.getInstance().getLocation() != null) { + return MogoLocationInfoServices.getInstance().getLocation().getCityName(); + } + return null; + } + + @Override + public int getGpsAccuracyStatus() { + if (MogoLocationInfoServices.getInstance().getLocation() != null) { + return MogoLocationInfoServices.getInstance().getLocation().getGpsAccuracyStatus(); + } + return 0; + } + + @Override + public int getSatellites() { + if (MogoLocationInfoServices.getInstance().getLocation() != null) { + return MogoLocationInfoServices.getInstance().getLocation().getSatellite(); + } + return 0; + } + + @Override + public int getCarStatus() { + // 常开状态 + return 1; + } +} diff --git a/app/src/main/res/layout/activity_location.xml b/app/src/main/res/layout/activity_location.xml new file mode 100644 index 0000000..f847c2c --- /dev/null +++ b/app/src/main/res/layout/activity_location.xml @@ -0,0 +1,23 @@ + + + +