fix: 解决冲突

This commit is contained in:
xiaoyan 2023-03-23 15:59:28 +08:00
commit 8755b70705
13 changed files with 261 additions and 31 deletions

View File

@ -17,8 +17,8 @@ android {
applicationId "com.navinfo.outdoor"
minSdkVersion 24
targetSdkVersion 30
versionCode 48
versionName "8.230309"
versionCode 49
versionName "8.230320-正式版"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {

View File

@ -84,6 +84,7 @@ import com.navinfo.outdoor.util.LocationLifeCycle;
import com.navinfo.outdoor.util.MyLocation;
import com.navinfo.outdoor.util.MyTecentLocationSource;
import com.navinfo.outdoor.util.NaviUtils;
import com.navinfo.outdoor.util.PicturesSpeedCheck;
import com.navinfo.outdoor.util.PreserveUtils;
import com.navinfo.outdoor.util.SystemTTS;
import com.navinfo.outdoor.util.TencentLocationObtain;
@ -239,10 +240,12 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
private boolean startMatchEnableDirection = true; // 是否启用方向匹配起点
private Logger logger = XLogUtils.Companion.getInstance().getAutoTakePictureLogWriter();
private ImageView imgLocationType;
private PicturesSpeedCheck speedCheck;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
speedCheck = new PicturesSpeedCheck();
SharedPreferences sharedPreferences = getSharedPreferences("pic", Context.MODE_PRIVATE);
BRIGHTNESS = sharedPreferences.getInt("brightness", 40);
FRAMENESS = sharedPreferences.getInt("framness", 30);
@ -505,7 +508,10 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
@Override
public void onMapClick(LatLng latLng) {
Message msg = handler.obtainMessage(0x105);
msg.obj = TencentLocationObtain.obtainTecentLocation(latLng);
Location location = new Location("GPS");
location.setLongitude(latLng.getLongitude());
location.setLatitude(latLng.getLatitude());
msg.obj = TencentLocationObtain.obtainTecentLocation(location);
handler.sendMessage(msg);
}
});
@ -571,6 +577,13 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
return;
}
// 道路任务增加检查
// 检测到当前车辆未移动则无需进行拍摄
if (!speedCheck.checkIsMove(LocationLifeCycle.getInstance().getMainLocation(), GPSUtils.getInstance(AutoTakePictureActivity.this).getSateliteCount())) {
com.github.lazylibrary.util.ToastUtils.showToast(AutoTakePictureActivity.this, "车辆静止中,暂停拍摄!");
return;
}
File tmpPicFolder = new File(tmpPicFoldPath);
if (!tmpPicFolder.exists()) {
tmpPicFolder.mkdirs();

View File

@ -36,10 +36,6 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@ -228,8 +224,7 @@ public class HomeActivity extends BaseActivity {
EventBus.getDefault().post(obtain);
} else if (tab.getPosition() == 1) {
Message obtain = Message.obtain();
obtain.what = Constant.STAY_SUBMIT_ITEM;
obtain.obj = true;
obtain.what = Constant.SWITCH_RECORFER_ITEM; // 发送消息给Recorder界面根据子tab的选项请求数据
EventBus.getDefault().post(obtain);
// 待提交页面暂时不需要获取当用户在记录tab下点击已提交后再去请求 #2023-0216

View File

@ -50,6 +50,7 @@ import com.navinfo.outdoor.util.LocationLifeCycle;
import com.navinfo.outdoor.util.MyLocation;
import com.navinfo.outdoor.util.MyTecentLocationSource;
import com.navinfo.outdoor.util.SensorOritationLifecycle;
import com.navinfo.outdoor.util.PicturesSpeedCheck;
import com.navinfo.outdoor.util.SystemTTS;
import com.navinfo.outdoor.util.TimestampUtil;
import com.navinfo.outdoor.util.ToastUtils;
@ -162,6 +163,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
private SimpleDateFormat formatter;
private SensorOritationLifecycle sensorOritationLifecycle;
private TextView tvDegrees;
private PicturesSpeedCheck speedCheck;
private Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
@ -202,6 +204,7 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
tvDegrees.setText("x:"+xDegree+"\ny:"+yDegree+"\nz:"+zDegree);
}
});
speedCheck = new PicturesSpeedCheck();
}
@Override
@ -502,6 +505,14 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
} else {
isOration = false;
}
// 道路任务增加检查
if (type == 4) {
// 检测到当前车辆未移动则无需进行拍摄
if (!speedCheck.checkIsMove(LocationLifeCycle.getInstance().getMainLocation(), GPSUtils.getInstance(PicturesActivity.this).getSateliteCount())) {
com.github.lazylibrary.util.ToastUtils.showToast(PicturesActivity.this, "车辆静止中,暂停拍摄!");
return;
}
}
if (pictureEmitter!=null) {
pictureEmitter.onNext(result);
@ -727,6 +738,8 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
0, //目标倾斜角[0.0 ~ 45.0] (垂直地图时为0)
0)); //目标旋转角 0~360° (正北方为0)
tencentMap.animateCamera(cameraSigma);
} else {
ToastUtils.Message(this, "当前定位方式无法获取位置信息!");
}
setLocMarkerStyle(LOCATION_TYPE_LOCATION_ROTATE);
break;
@ -734,8 +747,10 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
imgLocationType.setSelected(!imgLocationType.isSelected());
if (imgLocationType.isSelected()) { // 选中状态切换为GPS为主定位
LocationLifeCycle.getInstance().setMainLocationFrom(LocationLifeCycle.LOCATION_FROM.ORIGIN);
ToastUtils.Message(PicturesActivity.this, "切换为GPS定位");
} else {
LocationLifeCycle.getInstance().setMainLocationFrom(LocationLifeCycle.LOCATION_FROM.TENCENT);
ToastUtils.Message(PicturesActivity.this, "切换为网络定位");
}
break;
}
@ -962,11 +977,20 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
sb.append(index == -1 ? 0 : index);//個數
startVideoIndex = index == -1 ? 0 : index;
sb.append(",");
sb.append(LocationLifeCycle.getInstance().getMainLocation().getLatitude());
sb.append(",");
sb.append(LocationLifeCycle.getInstance().getMainLocation().getLongitude());
sb.append(",");
sb.append(LocationLifeCycle.getInstance().getMainLocation().getBearing());
if (LocationLifeCycle.getInstance().getMainLocation()!=null) {
sb.append(LocationLifeCycle.getInstance().getMainLocation().getLatitude());
sb.append(",");
sb.append(LocationLifeCycle.getInstance().getMainLocation().getLongitude());
sb.append(",");
sb.append(LocationLifeCycle.getInstance().getMainLocation().getBearing());
} else {
sb.append(LocationLifeCycle.getInstance().getTencentLocation().getLatitude());
sb.append(",");
sb.append(LocationLifeCycle.getInstance().getTencentLocation().getLongitude());
sb.append(",");
sb.append(LocationLifeCycle.getInstance().getTencentLocation().getBearing());
ToastUtils.Message(PicturesActivity.this, "主定位方式无法获取位置信息,使用腾讯定位记录当前位置!");
}
sb.append(",");
int gpsRssi = GPSUtils.getInstance(PicturesActivity.this).getSateliteCount();
if (gpsRssi == 0) {
@ -1031,7 +1055,10 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
private boolean isSpeedLimitTips = false;
private void initSpeed() {
if (isSpeedLimitTips == true) {
if (!systemTTS.isSpeaking()) {
isSpeedLimitTips = false;
}
if (isSpeedLimitTips == true || LocationLifeCycle.getInstance().getMainLocation() == null) {
return;
}
float speed = LocationLifeCycle.getInstance().getMainLocation().getSpeed();///
@ -1160,7 +1187,11 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
*/
public void initMarker(boolean isOration) {
LatLng latLng = null;
latLng = new LatLng(LocationLifeCycle.getInstance().getMainLocation().getLatitude(), LocationLifeCycle.getInstance().getMainLocation().getLongitude());
if (LocationLifeCycle.getInstance().getMainLocation()!=null) {
latLng = new LatLng(LocationLifeCycle.getInstance().getMainLocation().getLatitude(), LocationLifeCycle.getInstance().getMainLocation().getLongitude());
} else {
latLng = new LatLng(LocationLifeCycle.getInstance().getTencentLocation().getLatitude(), LocationLifeCycle.getInstance().getTencentLocation().getLongitude());
}
BitmapDescriptor pileDescriptor = BitmapDescriptorFactory
.fromResource(R.drawable.circle);
Marker marker = tencentMap.addMarker(new MarkerOptions(latLng)

View File

@ -153,6 +153,7 @@ public class Constant {
public static final int EVENT_WHAT_CHANGE_SLIDING_STATE=62;// 改变抽屉的状态
public static final int EVENT_WHAT_START_DRAW_LINE=63;// 开始绘制参考线
public static final int EVENT_WHAT_FINISH_DRAW_LINE=64;// 完成绘制参考线
public static final int SWITCH_RECORFER_ITEM=65;//记录界面请求数据提醒
public static final String INTENT_POI_VIDEO_TYPE = "poi_video_type";
public static int NUMBER = 200; //任务个数
public static int LIMIT_TYPE = -1; //权限类型普通任务-0专属任务-1

View File

@ -20,6 +20,7 @@ import com.lzy.okgo.cookie.CookieJarImpl;
import com.lzy.okgo.cookie.store.DBCookieStore;
import com.lzy.okgo.interceptor.HttpLoggingInterceptor;
import com.lzy.okgo.model.HttpHeaders;
import com.navinfo.outdoor.util.CrashHandler;
import com.tencent.map.navi.TencentNavi;
import com.tencent.navi.surport.utils.DeviceUtils;
import com.tencent.tencentmap.mapsdk.maps.TencentMapInitializer;
@ -68,6 +69,7 @@ public class UserApplication extends Application {
// 初始化对话框组件
DialogX.init(this);
DialogX.globalStyle = new MIUIStyle();
CrashHandler.getInstance().init();
}
public static UserApplication getUserApplication() {

View File

@ -7,6 +7,7 @@ import android.os.Message;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
@ -18,6 +19,7 @@ import com.navinfo.outdoor.base.BaseFragment;
import com.navinfo.outdoor.util.NoSlideViewPager;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@ -29,6 +31,7 @@ import java.util.Objects;
public class RecordFragment extends BaseFragment {
private final String[] names = {"待提交", "已提交"};
private TabLayout tabRecord;
public static RecordFragment newInstance(Bundle bundle) {
RecordFragment fragment = new RecordFragment();
@ -44,7 +47,7 @@ public class RecordFragment extends BaseFragment {
@Override
protected void initView() {
super.initView();
TabLayout tabRecord = findViewById(R.id.tab_record);
tabRecord = findViewById(R.id.tab_record);
NoSlideViewPager vpRecord = findViewById(R.id.vp_record);
ArrayList<Fragment> fragments = new ArrayList<>();
// 待提交
@ -105,9 +108,37 @@ public class RecordFragment extends BaseFragment {
super.onPause();
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().register(this);
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().unregister(this);
}
}
@Subscribe
public void onEvent(Message data) {
if (data.what == Constant.SWITCH_RECORFER_ITEM) {
if (tabRecord.getSelectedTabPosition() == 0) {
Message obtain = Message.obtain();
obtain.what = Constant.STAY_SUBMIT_ITEM;
obtain.obj = true;
EventBus.getDefault().post(obtain);
} else {
Message obtain1 = Message.obtain();
obtain1.what = Constant.HAS_SUBMIT_ITEM;
obtain1.obj = true;
EventBus.getDefault().post(obtain1);
}
}
}
}

View File

@ -0,0 +1,92 @@
package com.navinfo.outdoor.util;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Looper;
import android.os.SystemClock;
import android.widget.Toast;
import com.elvishew.xlog.XLog;
import com.navinfo.outdoor.api.UserApplication;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
public class CrashHandler implements Thread.UncaughtExceptionHandler {
private static volatile CrashHandler INSTANCE;
private CrashHandler() {
}
public static CrashHandler getInstance() {
if (INSTANCE == null) {
synchronized (CrashHandler.class) {
if (INSTANCE == null) {
synchronized (CrashHandler.class) {
INSTANCE = new CrashHandler();
}
}
}
}
return INSTANCE;
}
private Thread.UncaughtExceptionHandler mDefaultHandler;
/**
* 初始化默认异常捕获
*/
public void init() {
// 获取默认异常处理器
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
// 将当前类设为默认异常处理器
Thread.setDefaultUncaughtExceptionHandler(this);
}
@Override
public void uncaughtException(Thread t, Throwable e) {
if (handleException(e)) {
Toast.makeText(UserApplication.getUserApplication(), "抱歉,出现不可预知错误,请联系工作人员!", Toast.LENGTH_SHORT).show();
// 已经处理,APP重启
restartApp();
} else {
// 如果不处理,则调用系统默认处理异常,弹出系统强制关闭的对话框
if (mDefaultHandler != null) {
mDefaultHandler.uncaughtException(t, e);
}
}
}
private boolean handleException(Throwable e) {
if (e == null) {
return false;
}
Writer writer = new StringWriter();
PrintWriter pw = new PrintWriter(writer);
e.printStackTrace(pw);
pw.close();
String result = writer.toString();
// 打印出错误日志
XLog.e(result);
return true;
}
/**
* 1s后让APP重启
*/
private void restartApp() {
Intent intent = UserApplication.getUserApplication().getPackageManager()
.getLaunchIntentForPackage(UserApplication.getUserApplication().getPackageName());
PendingIntent restartIntent = PendingIntent.getActivity(UserApplication.getUserApplication(), 0, intent, 0);
AlarmManager mgr = (AlarmManager) UserApplication.getUserApplication().getSystemService(Context.ALARM_SERVICE);
// 1秒钟后重启应用
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, restartIntent);
System.exit(0);
}
}

View File

@ -25,6 +25,9 @@ import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import com.navinfo.outdoor.api.Constant;
import com.tencent.map.fusionlocation.model.TencentGeoLocation;
import com.tencent.map.geolocation.TencentLocation;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import org.greenrobot.eventbus.EventBus;
@ -171,10 +174,12 @@ public class GPSUtils {
Log.i(TAG, "纬度:" + location.getLatitude());
Log.i(TAG, "海拔:" + location.getAltitude());
TencentLocation tencentLocation = TencentLocationObtain.obtainTecentLocation(location);
Message currentLocationMsg = Message.obtain();
currentLocationMsg.what = Constant.EVENT_WHAT_LOCATION_CHANGE;
currentLocationMsg.arg1 = LocationLifeCycle.LOCATION_FROM.ORIGIN.ordinal(); // 设置定位来源
currentLocationMsg.obj = location;
currentLocationMsg.obj = tencentLocation;
EventBus.getDefault().post(currentLocationMsg);
}

View File

@ -24,7 +24,7 @@ public class LocationLifeCycle implements DefaultLifecycleObserver {
private Context mContext;
private LOCATION_FROM mainLocationFrom = LOCATION_FROM.TENCENT/*主要位置源*/, referenceLocationFrom = LOCATION_FROM.ORIGIN/*参考位置源*/;
private TencentLocation tencentLocation; // 腾讯定位获取到的最新位置信息
private Location gpsLocation; // 原生系统获取到的最新位置
private TencentLocation gpsLocation; // 原生系统获取到的最新位置
private List<LocationSource.OnLocationChangedListener> locationChangedListenerList;
private static LocationLifeCycle instance;
@ -81,11 +81,21 @@ public class LocationLifeCycle implements DefaultLifecycleObserver {
public void onEventMessageMainThread(Message msg) {
if (msg.what == Constant.EVENT_WHAT_LOCATION_CHANGE) { // 用户位置更新
if (msg.arg1 == LOCATION_FROM.ORIGIN.ordinal()) {
gpsLocation = (Location) msg.obj;
gpsLocation = (TencentLocation) msg.obj;
if (msg.arg1 == mainLocationFrom.ordinal()) { // 如果当前定位方式是主要定位方式
MyLocation location = new MyLocation(gpsLocation.getProvider(), gpsLocation);
//设置经纬度以及精度
location.setLatitude(gpsLocation.getLatitude());
location.setLongitude(gpsLocation.getLongitude());
if (gpsLocation.getBearing()!=0) {
location.setBearing(gpsLocation.getBearing());
} else {
location.setBearing((float) gpsLocation.getDirection());
}
location.setAccuracy(gpsLocation.getAccuracy());
if (locationChangedListenerList!=null) {
for (LocationSource.OnLocationChangedListener locationChangedListener:locationChangedListenerList) {
locationChangedListener.onLocationChanged(gpsLocation);
locationChangedListener.onLocationChanged(location);
}
}
}

View File

@ -0,0 +1,43 @@
package com.navinfo.outdoor.util
import com.tencent.tencentmap.mapsdk.maps.model.LatLng
class PicturesSpeedCheck {
val pointList = mutableListOf<MyLocation>()
val LIST_SIZE = 5
val DISTANCE = 2
/**
* 与前面的4个点做检查如果当前点位距离前面4个点的距离超过阈值且当前卫星信号强度为中以上8则返回false
* */
fun checkIsMove(myLocation: MyLocation, sateliteCount: Int/*卫星颗数*/): Boolean {
pointList.add(myLocation)
if (pointList.size<5) { // 点位小于4个不做判断默认为运动中
return true
}
if (pointList.size>5) { // 如果点位信息超过5个移除第一个数据
pointList.removeAt(0)
}
if (sateliteCount<=3) { // 卫星颗数小于等于3说明当前卫星信号弱则忽略距离因素认为车辆在移动中
return true
}
var distance = 0.0
for (index in pointList.indices) {
if (index+1<pointList.size) {
distance += GeometryTools.distanceToDouble(
LatLng(
pointList[index].latitude,
pointList[index].longitude
),
LatLng(pointList[index + 1].latitude, pointList[index + 1].longitude)
)
}
if (distance>DISTANCE) { // 如果距离已经大于设置的距离阈值,无需再计算后面的点位,车辆运动中
return true
}
}
return false
}
}

View File

@ -97,5 +97,11 @@ public class SystemTTS extends UtteranceProgressListener implements TTS, TextToS
}
public boolean isSpeaking() {
if (textToSpeech!=null) {
return textToSpeech.isSpeaking();
}
return false;
}
}

View File

@ -1,5 +1,6 @@
package com.navinfo.outdoor.util;
import android.location.Location;
import android.os.Bundle;
import com.tencent.map.geolocation.TencentLocation;
@ -10,11 +11,11 @@ import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import java.util.List;
public class TencentLocationObtain {
public static TencentLocation obtainTecentLocation(LatLng latLng) {
public static TencentLocation obtainTecentLocation(Location location) {
return new TencentLocation() {
@Override
public String getProvider() {
return "NetWork";
return location.getProvider();
}
@Override
@ -29,22 +30,22 @@ public class TencentLocationObtain {
@Override
public double getLatitude() {
return latLng.getLatitude();
return location.getLatitude();
}
@Override
public double getLongitude() {
return latLng.getLongitude();
return location.getLongitude();
}
@Override
public double getAltitude() {
return latLng.getAltitude();
return location.getAltitude();
}
@Override
public float getAccuracy() {
return 100;
return location.getAccuracy();
}
@Override
@ -109,22 +110,22 @@ public class TencentLocationObtain {
@Override
public float getBearing() {
return 0;
return location.getBearing();
}
@Override
public float getSpeed() {
return 0;
return location.getSpeed();
}
@Override
public long getTime() {
return 0;
return location.getTime();
}
@Override
public long getElapsedRealtime() {
return 0;
return location.getElapsedRealtimeNanos();
}
@Override