fix bug of location to upload socket server

This commit is contained in:
zhongchao
2021-11-17 17:14:22 +08:00
parent d3d355c442
commit 444b7a4c68
23 changed files with 1113 additions and 25 deletions

View File

@@ -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();
}
}

View File

@@ -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);

View File

@@ -76,6 +76,7 @@ public class MoGoApplication extends MultiDexApplication {
}
});
clientConfig.setUseOriginSocket(true);
// 初始化SDK可以设置状态回调来监听
MoGoAiCloudClient.getInstance().init(this, clientConfig);
}

View File

@@ -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");
}
}

View File

@@ -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;
}
}