fix: 修改bug,增加自动捕捉日志记录

This commit is contained in:
xiaoyan-5800X 2022-12-07 02:10:39 +08:00
parent 7c22a5ca72
commit 559fe05db2
13 changed files with 183 additions and 21 deletions

View File

@ -51,5 +51,10 @@
<option name="name" value="maven4" />
<option name="url" value="https://oss.sonatype.org/content/groups/public" />
</remote-repository>
<remote-repository>
<option name="id" value="maven5" />
<option name="name" value="maven5" />
<option name="url" value="https://maven.google.com/" />
</remote-repository>
</component>
</project>

View File

@ -12,8 +12,8 @@ android {
applicationId "com.navinfo.outdoor"
minSdkVersion 23
targetSdkVersion 30
versionCode 34
versionName "8.221130"
versionCode 35
versionName "8.221206"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
@ -163,5 +163,10 @@ dependencies {
implementation 'com.wanghong.webpnative:webpnative:0.1.0'
// https://github.com/teprinciple/MailSender
implementation 'com.teprinciple:mailsender:1.2.0'
// // https://github.com/JiongBull/jlog/blob/master/README_ZH.md
// implementation 'com.github.JiongBull:jlog:0.1.0'
// // https://github.com/JiongBull/jlog-storage-qiniu
// implementation 'com.github.JiongBull:jlog-storage-qiniu:0.1.0'
// https://github.com/elvishew/xLog/blob/master/README_ZH.md
implementation 'com.elvishew:xlog:1.10.1'
}

View File

@ -35,7 +35,17 @@ import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import com.elvishew.xlog.Logger;
import com.elvishew.xlog.XLog;
import com.elvishew.xlog.flattener.ClassicFlattener;
import com.elvishew.xlog.printer.AndroidPrinter;
import com.elvishew.xlog.printer.ConsolePrinter;
import com.elvishew.xlog.printer.Printer;
import com.elvishew.xlog.printer.file.FilePrinter;
import com.elvishew.xlog.printer.file.naming.DateFileNameGenerator;
import com.elvishew.xlog.printer.file.naming.FileNameGenerator;
import com.github.lazylibrary.util.FileUtils;
import com.github.lazylibrary.util.NetWorkUtils;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@ -146,9 +156,11 @@ import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;
import java.util.function.Predicate;
@ -220,6 +232,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
private ImageView imgNaviDistance/*自动规划到距离最近的数据开关*/, imgRoadDirection; // 道路方向匹配开关
private Polyline currentNaviLine; // 当前界面上正显示的导航路径线重绘路径时需要清除此前已绘制的路径
private boolean startMatchEnableDirection = true; // 是否启用方向匹配起点
private Logger logger;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -696,7 +709,9 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
@Override
public void onError(Throwable e) {
if (AutoTakePictureActivity.this!=null) {
write2Log("领取任务失败:", e.getMessage()+",网络状态-:"+ NetWorkUtils.getNetworkTypeName(AutoTakePictureActivity.this));
}
}
@Override
@ -711,6 +726,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
private double minDistance = MATCH_START_BUFFER_DISTANCE; // 最小距离需要在匹配过程点时判断哪个任务是距离最小的
private void startMatchRoadLink(Point currentPoint) {
if (roadLinkEntityList == null/*没有需要匹配的道路数据*/ || currentPoint == null/*没有位置信息*/) {
write2Log("开始匹配:", "roadLinkEntityList == null:"+(roadLinkEntityList == null)+",currentPoint == null"+(currentPoint == null));
return;
}
double[] speedAndBearing = getSpeedAndBearing(currentPoint);
@ -722,17 +738,27 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
matchMiddleDistance = MATCH_BUFFER_DISTANCE*1.5;
}
// 此处开始匹配起点
write2Log("开始匹配起点位置:", "currentLocation:"+currentPoint.toString()+",可匹配数据个数:"+roadLinkEntityList.size());
List<RoadMatchEntity> matchStartList = roadLinkEntityList.stream()
// 筛选当前任务与起点距离
.filter(it-> GeometryTools.createGeometry(it.getsPoint()).distance(currentPoint)<MATCH_START_BUFFER_DISTANCE)
.filter(it-> {
if (GeometryTools.createGeometry(it.getsPoint()).distance(currentPoint)<MATCH_START_BUFFER_DISTANCE) {
return true;
} else {
return false;
}
})
// 筛选方向
.filter(it-> {
if (startMatchEnableDirection) {
double dataBearing = it.getAngle();
if (currentBearing!=0&&(Math.abs(dataBearing-currentBearing)<=90 || Math.abs(dataBearing-currentBearing)>=270)) {
return true;
} else {
// 根据方向判定无法匹配
write2Log("方向不匹配:", "currentBearing:"+currentBearing+",数据角度:"+dataBearing+",数据id:"+it.getDataDetail().getId());
return false;
}
return false;
} else {
return true;
}
@ -764,6 +790,8 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
// 将匹配到的数据加入到已匹配列表中
roadMatchEntityList.addAll(matchStartList);
} else {
write2Log("匹配起点数据为空:", "当前位置为:"+currentPoint.toString()+"当前角度:"+currentBearing);
}
// 尝试用当前位置点匹配已经匹配到的roadLink如果能匹配到需要将该点记录如果无法匹配则需要评估已匹配的link是否需要被剔除
@ -1114,6 +1142,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
* 初始化领取任务的管理栈
* */
private Observable<PoiEntity> receiverRoadTask(RoadMatchEntity entity) {
write2Log("开始领取任务:", entity.getId()+"");
return Observable.just(entity).subscribeOn(Schedulers.io()).observeOn(Schedulers.computation())
.filter(roadMatchEntity -> roadMatchEntity!=null)
.map(new Function<RoadMatchEntity, PoiEntity>() {
@ -1162,6 +1191,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
}
} else if (taskByNetBean.getCode() == 230) { // Token过期
systemTTS.playText("注意Token过期请重新登陆");
write2Log("领取任务失败:", "Token过期"+taskByNetBean.getMessage());
FlushTokenUtil.flushToken(AutoTakePictureActivity.this);
Message msg = handler.obtainMessage(0x103);
msg.obj = entity;
@ -1169,6 +1199,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
} else {
systemTTS.playText("注意,领取任务失败!");
ToastUtils.Message(AutoTakePictureActivity.this,taskByNetBean.getMessage());
write2Log("领取任务失败:", "领取失败:"+taskByNetBean.getMessage());
Message msg = handler.obtainMessage(0x103);
msg.obj = entity;
handler.sendMessageDelayed(msg, 10*1000); // 10秒后重试
@ -2073,6 +2104,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
public void onEventMessageMainThread(Message msg) {
if (msg.what == Constant.EVENT_WHAT_LOCATION_CHANGE) { // 用户位置更新
if (!locationEnable) {
write2Log("onEventMessageMainThread", "关闭了获取GPS定位开关");
return;
}
TencentLocation tencentLocation = (TencentLocation) msg.obj;
@ -2087,10 +2119,41 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
// 判断当前点位和上一个点位的距离如果距离过近忽略该点
Point currentPoint = (Point) GeometryTools.createGeometry(new LatLng(tencentLocation.getLatitude(), tencentLocation.getLongitude()));
if (lastPositionPoint!=null&&lastPositionPoint.distance(currentPoint)<5e-7) { // 如果当前点小于最小距离阈值过滤该数据
write2Log("onEventMessageMainThread", "距离上一点位距离过近currentPoint-"+currentPoint.toString()+"lastPositionPoint:"+lastPositionPoint.toString());
return;
}
lastPositionPoint = currentPoint;
startMatchRoadLink(currentPoint);
}
}
private void write2Log(String tag, String log) {
if (logger == null) {
Printer filePrinter = new FilePrinter // 打印日志到文件的打印器
.Builder(Constant.LOG_FOLDER) // 指定保存日志文件的路径
.fileNameGenerator(new DateFileNameGenerator() {
ThreadLocal<SimpleDateFormat> mLocalDateFormat = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd", Locale.US);
}
};
@Override
public boolean isFileNameChangeable() {
return true;
}
@Override
public String generateFileName(int logLevel, long timestamp) {
SimpleDateFormat sdf = mLocalDateFormat.get();
sdf.setTimeZone(TimeZone.getDefault());
return "AutoTakePicture-"+sdf.format(new Date(timestamp));
}
}) // 指定日志文件名生成器默认为 ChangelessFileNameGenerator("log")
.flattener(new ClassicFlattener())
.build();
logger = XLog.printers(filePrinter).build();
}
logger.v(null, tag, log);
}
}

View File

@ -1,8 +1,21 @@
package com.navinfo.outdoor.activity;
import com.elvishew.xlog.LogConfiguration;
import com.elvishew.xlog.LogLevel;
import com.elvishew.xlog.XLog;
import com.elvishew.xlog.flattener.ClassicFlattener;
import com.elvishew.xlog.printer.AndroidPrinter;
import com.elvishew.xlog.printer.ConsolePrinter;
import com.elvishew.xlog.printer.Printer;
import com.elvishew.xlog.printer.file.FilePrinter;
import com.elvishew.xlog.printer.file.backup.BackupStrategy2;
import com.elvishew.xlog.printer.file.backup.FileSizeBackupStrategy2;
import com.elvishew.xlog.printer.file.backup.NeverBackupStrategy;
import com.elvishew.xlog.printer.file.clean.FileLastModifiedCleanStrategy;
import com.elvishew.xlog.printer.file.naming.DateFileNameGenerator;
import com.elvishew.xlog.printer.file.naming.LevelFileNameGenerator;
import com.github.lazylibrary.util.ShellUtils;
import com.google.gson.Gson;
import com.hjq.permissions.XXPermissions;
import com.kongzue.dialog.interfaces.OnDialogButtonClickListener;
import com.kongzue.dialog.util.BaseDialog;
import com.kongzue.dialog.util.DialogSettings;
@ -45,7 +58,6 @@ import com.google.android.material.tabs.TabLayout;
import com.gyf.immersionbar.ImmersionBar;
import com.teprinciple.mailsender.Mail;
import com.teprinciple.mailsender.MailSender;
import com.umeng.message.PushAgent;
import com.umeng.message.UmengNotificationClickHandler;
import com.umeng.message.entity.UMessage;
@ -104,6 +116,24 @@ public class HomeActivity extends BaseActivity {
// 检测用户是否为虚拟定位
boolean result = handler.sendEmptyMessageDelayed(0x101, 1000*60*(int)(10*Math.random()));
Log.d("HomeActivity", "作弊检查:"+result);
LogConfiguration logConfiguration = new LogConfiguration.Builder()
// .enableStackTrace(5)
.enableBorder()
.tag("OutDoor").build();
Printer androidPrinter = new AndroidPrinter(true); // 通过 android.util.Log 打印日志的打印器
Printer consolePrinter = new ConsolePrinter(); // 通过 System.out 打印日志到控制台的打印器
Printer filePrinter = new FilePrinter // 打印日志到文件的打印器
.Builder(Constant.LOG_FOLDER) // 指定保存日志文件的路径
.fileNameGenerator(new LevelFileNameGenerator()) // 指定日志文件名生成器默认为 ChangelessFileNameGenerator("log")
.flattener(new ClassicFlattener())
.build();
// 初始化XLog
XLog.init( // 初始化 XLog
logConfiguration, // 指定日志配置如果不指定会默认使用 new LogConfiguration.Builder().build()
androidPrinter, // 添加任意多的打印器如果没有添加任何打印器会默认使用 AndroidPrinter(Android)/ConsolePrinter(java)
consolePrinter,
filePrinter);
} else {
finish();
}

View File

@ -239,9 +239,9 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
});
RadioGroup radioGroupPicture = findViewById(R.id.radio_group_picture);
RadioButton radioBtnHand = findViewById(R.id.radio_btn_hand);
RadioButton radioBtnHalfSec = findViewById(R.id.radio_btn_half_sec);
RadioButton radioBtnAuto = findViewById(R.id.radio_btn_auto);
RadioButton radioBtnAutoSec = findViewById(R.id.radio_btn_auto_sec);
RadioButton radioBtnHalfSec = findViewById(R.id.radio_btn_half_sec);
if (type == 3) {//poiVideo 1秒
ivPicVideoImage.setVisibility(View.VISIBLE);
ivPicRoadImage.setVisibility(View.GONE);
@ -252,6 +252,10 @@ public class PicturesActivity extends BaseActivity implements View.OnClickListen
ivPicVideoImage.setVisibility(View.GONE);
radioPicture = 4;
radioBtnHalfSec.setChecked(true);
// 道路采集时自动隐藏其他选项只保留自动0.5秒1张的设定
radioBtnHand.setVisibility(View.GONE);
radioBtnAuto.setVisibility(View.GONE);
radioBtnAutoSec.setVisibility(View.GONE);
}
radioGroupPicture.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override

View File

@ -11,6 +11,8 @@ import android.widget.RemoteViews;
import androidx.core.app.NotificationCompat;
import com.elvishew.xlog.LogLevel;
import com.elvishew.xlog.XLog;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheEntity;

View File

@ -174,7 +174,10 @@ public class MineFragment extends BaseFragment implements View.OnClickListener {
public void onError(Throwable e, int id) {
dismissLoadingDialog();
String message = e.getMessage();
assert message != null;
if (message == null) {
ToastUtils.Message(getActivity(), "获取余额失败,请重试!");
return;
}
if (message.equals("timeout") || message.equals("Read time out")) {
ToastUtils.Message(getActivity(), "请求超时");
} else {

View File

@ -110,6 +110,11 @@ public class PhotoFragment extends BaseFragment implements View.OnClickListener
List<File> fileArrayList = new ArrayList<>();
if (fileListByUUID.size() >= 2) {
for (int i = 0; i < fileListByUUID.size(); i++) {
File file = fileListByUUID.get(i);
// 过滤分包数据,如果不是txt和照片文件则自动跳过
if (!file.getName().endsWith(".txt")&&!file.getName().endsWith(".webp")&&!file.getName().endsWith(".jpg")&&!file.getName().endsWith(".png")&&!file.getName().endsWith(".jpeg")) {
continue;
}
if (!fileListByUUID.get(i).getPath().endsWith("paper.txt")) {
fileArrayList.add(fileListByUUID.get(i));
} else {

View File

@ -417,12 +417,14 @@ public class AWMp4ParserHelper {
if (strings != null) {
for (int i = 0; i < strings.size(); i++) {
String[] split = strings.get(i).split(",");
LatLng latLng = new LatLng();
latLng.setLatitude(Double.valueOf(split[2]));
latLng.setLongitude(Double.valueOf(split[3]));
latLags.add(latLng);
if (split.length>3) {
LatLng latLng = new LatLng();
latLng.setLatitude(Double.valueOf(split[2]));
latLng.setLongitude(Double.valueOf(split[3]));
latLags.add(latLng);
}
}
if (strings.size() == 1) {
if (latLags.size() == 1) {
LatLng latLng = latLags.get(0);
latLags.add(latLng);
}

View File

@ -109,9 +109,12 @@ public class DataSaveUtils {
PoiDatabase.getInstance(mContext).getPoiDao().updatePoiEntity(poiEntity);
ToastUtils.Message(mContext, "数据:"+poiEntity.getName()+"已成功上传!");
}
if (body==null||body.isEmpty()) {
if (body==null) {
throw new Exception(response.getMessage());
}
if (body.isEmpty()) {
return new HashMap<>();
}
String[] needUploadStrIndex = body.split(",");
// 批量转换String为int
int[] needUploadIndex = new int[needUploadStrIndex.length];

View File

@ -0,0 +1,33 @@
package com.navinfo.outdoor.util;
import com.elvishew.xlog.printer.file.naming.DateFileNameGenerator;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
public class LogFileNameGenerate extends DateFileNameGenerator {
ThreadLocal<SimpleDateFormat> mLocalDateFormat = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd", Locale.US);
}
};
@Override
public boolean isFileNameChangeable() {
return true;
}
/**
* Generate a file name which represent a specific date.
*/
@Override
public String generateFileName(int logLevel, long timestamp) {
SimpleDateFormat sdf = mLocalDateFormat.get();
sdf.setTimeZone(TimeZone.getDefault());
return "default-"+sdf.format(new Date(timestamp));
}
}

View File

@ -5,7 +5,7 @@ import android.widget.Toast;
public class ToastUtils {
public static void Message(Activity context, String message) {
if (context!=null){
if (context!=null&&message!=null){
context.runOnUiThread(new Runnable() {
@Override
public void run() {

View File

@ -3,6 +3,10 @@ buildscript {
ext.anko_version = '0.10.1'//
ext.kotlin_version = '1.5.10'
repositories {
maven { url "https://jitpack.io" }
maven{
url "https://maven.google.com/"
}
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
// bug
maven { url 'https://repo1.maven.org/maven2/' }
@ -10,10 +14,9 @@ buildscript {
maven{
url "https://oss.sonatype.org/content/groups/public"
}
maven { url "https://jitpack.io" }
google()
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
@ -27,16 +30,20 @@ buildscript {
allprojects {
repositories {
maven { url 'https://jitpack.io' }
maven { url "https://jitpack.io" }
maven{
url "https://maven.google.com/"
}
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
// bug
maven { url 'https://repo1.maven.org/maven2/' }
//
maven{
url "https://oss.sonatype.org/content/groups/public"
}
jcenter()
google()
mavenCentral()
google()
}
}