diff --git a/app/src/main/java/com/navinfo/outdoor/activity/AutoTakePictureActivity.java b/app/src/main/java/com/navinfo/outdoor/activity/AutoTakePictureActivity.java index c23d3c7..8767be0 100644 --- a/app/src/main/java/com/navinfo/outdoor/activity/AutoTakePictureActivity.java +++ b/app/src/main/java/com/navinfo/outdoor/activity/AutoTakePictureActivity.java @@ -11,6 +11,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.location.Location; +import android.media.MediaPlayer; import android.os.Build; import android.os.Bundle; import android.os.Handler; @@ -182,7 +183,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic private List removables; // 地图上渲染的网络获取的道路任务 private List removablesLocality; // 地图上渲染的本地道路任务 private HashMap> removableHashMap; - private List roadLinkEntityList, roadMatchEntityList; + private List roadLinkEntityList/*请求到的待匹配道路数据*/, roadMatchEntityList/*已匹配起始点的道路数据*/; private int satelliteCount; // 卫星颗数 private final long UN_MATCH_TIME_MAX=30*1000; // 未匹配到的时间阈值,最长为30秒 private static double MATCH_BUFFER_DISTANCE=15e-5; // 匹配途经点用到的buffer距离,此处5米使用简易判断 @@ -202,6 +203,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic private boolean locationEnable=true; private ImageView imgViewSettingHook; // 调起隐藏设置的按钮 private TencentLocation oldCurrentLocation = null; + private MediaPlayer mediaPlayer; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -211,6 +213,8 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic // 设置当前界面亮度为40% setWindowBrightness(BRIGHTNESS); + // 初始化提示音播放器 + mediaPlayer=MediaPlayer.create(this, R.raw.ding); super.onCreate(savedInstanceState); } @@ -650,7 +654,9 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic matchStartDistance = MATCH_BUFFER_DISTANCE*1.5; } // 此处开始匹配起点 - List matchStartList = roadLinkEntityList.stream().filter(it-> GeometryTools.createGeometry(it.getsPoint()).distance(currentPoint) matchStartList = roadLinkEntityList.stream() + .filter(it-> GeometryTools.createGeometry(it.getsPoint()).distance(currentPoint) roadMatchEntityList.stream().noneMatch(roadMatchEntity -> o.getId()==roadMatchEntity.getId()) @@ -664,54 +670,91 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic // TODO:自动发送请求领取任务 receiverRoadTask(roadMatchEntity).subscribe(receiveObserver); }); + + // 语音提醒 + if (roadMatchEntityList.isEmpty()) { + // 当前没有已匹配的数据,提示用户“叮~捕捉任务” + mediaPlayer.start(); + systemTTS.playText("捕捉任务"); + } else { + // 当前存在已匹配的任务,有新匹配的任务,提示“叮~任务拍摄中” + mediaPlayer.start(); + systemTTS.playText("任务拍摄中"); + } + // 将匹配到的数据加入到已匹配列表中 roadMatchEntityList.addAll(matchStartList); } // 尝试用当前位置点匹配已经匹配到的roadLink,如果能匹配到,需要将该点记录,如果无法匹配,则需要评估已匹配的link是否需要被剔除 if (!roadMatchEntityList.isEmpty()) { + // 因为单个点位只能匹配一条任务,需要获取当前点位距离所有任务最近的距离 + roadMatchEntityList.stream().forEach(it->it.setCurrentLineDistance(GeometryTools.createGeometry(it.getGeometry()).distance(currentPoint))); + // 筛选出本次距离最近的线 + RoadMatchEntity minRoadMatchEntity = roadMatchEntityList.stream().min((o1, o2)-> { + if (o1.getCurrentLineDistance() unMatchList = new ArrayList<>(); Map finishEntityMap = new HashMap<>(); double finalMatchStartDistance = matchStartDistance; roadMatchEntityList.stream().forEach( roadMatchEntity -> { - boolean isMatch=GeometryTools.createGeometry(roadMatchEntity.getGeometry()).distance(currentPoint)< finalMatchStartDistance; // 当前点位是否可以和link匹配到 - if (isMatch) { // 可以匹配到 + double currentDistance = roadMatchEntity.getCurrentLineDistance(); + boolean isMatch=currentDistance<= finalMatchStartDistance; // 当前点位是否可以和link匹配到 + if (minRoadMatchEntity.getId() == roadMatchEntity.getId()&&isMatch) { // 可以匹配到,并且该条数据还是最近的点 roadMatchEntity.setMatchCount(roadMatchEntity.getMatchCount()+1); roadMatchEntity.setUnMatchCount(0); // 有匹配的数据,则连续未匹配个数归0 roadMatchEntity.getMatchPointList().add(new MyCoordinate(currentPoint.getX(), currentPoint.getY())); - // 匹配到终点、或匹配距离超过90% - if (roadMatchEntity.getMatchPointList().size()>=2&&GeometryTools.getLineStringByMyCoordinate(roadMatchEntity.getMatchPointList()).getLength()/roadMatchEntity.getLength()>=MATCH_CONFIRM_FINISH_BUFFER - || currentPoint.distance(GeometryTools.createGeometry(roadMatchEntity.getePoint()))<= finalMatchStartDistance) { - roadMatchEntity.setEndMathchTime(System.currentTimeMillis()); + double currentEndDistance = currentPoint.distance(GeometryTools.createGeometry(roadMatchEntity.getePoint())); // 当前距离终点的距离 + // 记录本次的匹配距离,如果本次匹配距离大于上一次,且上一次匹配距离不为0,则结束匹配,否则继续等待匹配,设置过EndMathchTime的数据即为可以结束匹配的数据,下一次如果未匹配,也可以结束 + if (roadMatchEntity.getEndMathchTime()>0/*endMatchTime不为0,说明该数据已经匹配到终点*/&¤tEndDistance>roadMatchEntity.getLastEndDistance()) { finishEntityMap.put(roadMatchEntity.getId(), roadMatchEntity); } - } else { // 无法匹配 - // 将无法匹配的点位个数记录到对象中 - roadMatchEntity.setUnMatchCount(roadMatchEntity.getUnMatchCount()+1); - roadMatchEntity.setMatchCount(0); - roadMatchEntity.getUnMatchPointList().add(new MyCoordinate(currentPoint.getX(), currentPoint.getY())); - // 判断当前是否存在已匹配的点 - if (roadMatchEntity.getMatchPointList().size()>1) { // 存在匹配的点超过1个,根据长度判断 - if (GeometryTools.getLineStringByMyCoordinate(roadMatchEntity.getMatchPointList()).getLength()/roadMatchEntity.getLength()>UNMATCH_GIVE_UP_DISTANCE_BUFFER) { - // 匹配距离超过20%,根据匹配点和未匹配点个数的对比率判断是否需要放弃 - if (((float)roadMatchEntity.getUnMatchPointList().size())/roadMatchEntity.getMatchPointList().size()>UNMATCH_COUNT_BUFFER) { - unMatchList.add(roadMatchEntity); + // 匹配到终点、或匹配距离超过90% + if (roadMatchEntity.getMatchPointList().size()>=2&&GeometryTools.getLineStringByMyCoordinate(roadMatchEntity.getMatchPointList()).getLength()/roadMatchEntity.getLength()>=MATCH_CONFIRM_FINISH_BUFFER + || currentEndDistance<= finalMatchStartDistance) { + roadMatchEntity.setEndMathchTime(System.currentTimeMillis()); + // 匹配到终点后,记录该条数据的最新一次匹配距离,当下一次匹配距离大于当前距离,则认为该数据完全匹配,结束匹配 + roadMatchEntity.setLastEndDistance(currentEndDistance); + } + } else { // 无法匹配,或当前道路并不是距离最近的数据 + // 该数据未匹配,但是如果此前已经匹配到结束点,则仍然认为匹配成功 + if (roadMatchEntity.getEndMathchTime()>0) { + finishEntityMap.put(roadMatchEntity.getId(), roadMatchEntity); + } else { + // 将无法匹配的点位个数记录到对象中 + roadMatchEntity.setUnMatchCount(roadMatchEntity.getUnMatchCount()+1); + roadMatchEntity.setMatchCount(0);// 设置连续匹配的数据个数为0 + roadMatchEntity.getUnMatchPointList().add(new MyCoordinate(currentPoint.getX(), currentPoint.getY())); + // 判断当前是否存在已匹配的点 + if (roadMatchEntity.getMatchPointList().size()>1) { // 存在匹配的点超过1个,根据长度判断 + if (GeometryTools.getLineStringByMyCoordinate(roadMatchEntity.getMatchPointList()).getLength()/roadMatchEntity.getLength()>UNMATCH_GIVE_UP_DISTANCE_BUFFER) { + // 匹配距离超过20%,根据匹配点和未匹配点个数的对比率判断是否需要放弃 + if (((float)roadMatchEntity.getUnMatchPointList().size())/roadMatchEntity.getMatchPointList().size()>UNMATCH_COUNT_BUFFER) { + unMatchList.add(roadMatchEntity); + } + } else {// 当前匹配距离不超过20%,则必须有连续多个点未匹配才可以放弃该Link + if (roadMatchEntity.getUnMatchCount()>UNMATCH_BUFFER_MIDDLE_BUFFER) { + unMatchList.add(roadMatchEntity); + } } - } else {// 当前匹配距离不超过20%,则必须有连续多个点未匹配才可以放弃该Link - if (roadMatchEntity.getUnMatchCount()>UNMATCH_BUFFER_MIDDLE_BUFFER) { - unMatchList.add(roadMatchEntity); - } - } - } else { // 从未匹配过的数据 - // 未匹配个数超过指定阈值,也认为数据不匹配 - if (roadMatchEntity.getMatchPointList().size()==0) { // 已匹配的个数为0 - if (roadMatchEntity.getUnMatchCount()>UNMATCH_BUFFER_START_BUFFER) { - unMatchList.add(roadMatchEntity); - } - } else if (roadMatchEntity.getMatchPointList().size()==1) { // 已匹配的个数为1 - if (roadMatchEntity.getUnMatchCount()>UNMATCH_BUFFER_MIDDLE_BUFFER) { - unMatchList.add(roadMatchEntity); + } else { // 从未匹配过的数据 + // 未匹配个数超过指定阈值,也认为数据不匹配 + if (roadMatchEntity.getMatchPointList().size()==0) { // 已匹配的个数为0 + if (roadMatchEntity.getUnMatchCount()>UNMATCH_BUFFER_START_BUFFER) { + unMatchList.add(roadMatchEntity); + } + } else if (roadMatchEntity.getMatchPointList().size()==1) { // 已匹配的个数为1 + if (roadMatchEntity.getUnMatchCount()>UNMATCH_BUFFER_MIDDLE_BUFFER) { + unMatchList.add(roadMatchEntity); + } } } } @@ -727,6 +770,9 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic } // TODO 完成的entity数据,需要自动生成对应的数据,还需要自动复制对应的照片,通知服务器采集完成 finishRoadTask(finishEntityMap); + // 语音提示用户 + mediaPlayer.start(); + systemTTS.playText("拍摄完成"); } if (!unMatchList.isEmpty()) { @@ -1278,6 +1324,9 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic if (gpsUtils!=null) { gpsUtils.unRegisterAllListener(); } + if (mediaPlayer!=null) { + mediaPlayer.release(); + } } @Override diff --git a/app/src/main/java/com/navinfo/outdoor/bean/RoadMatchEntity.java b/app/src/main/java/com/navinfo/outdoor/bean/RoadMatchEntity.java index ed0b594..588f63d 100644 --- a/app/src/main/java/com/navinfo/outdoor/bean/RoadMatchEntity.java +++ b/app/src/main/java/com/navinfo/outdoor/bean/RoadMatchEntity.java @@ -30,7 +30,8 @@ public class RoadMatchEntity implements Serializable { private String ePoint; // 起点 private long startMatchTime; // 开始匹配的时间 private long endMathchTime; // 结束匹配的时间 - private double lastDistance=0; // 上次匹配到的距离 + private double currentLineDistance=0f; // 当前匹配到的距离道路线的距离 + private double lastEndDistance=0f; // 上次匹配到的距离终点的距离 private int matchCount; // <连续>匹配到的点位个数 private int unMatchCount; // <连续>未匹配到的点位个数 private List matchPointList = new ArrayList<>(); // 已匹配的点位列表 @@ -113,12 +114,12 @@ public class RoadMatchEntity implements Serializable { this.endMathchTime = endMathchTime; } - public double getLastDistance() { - return lastDistance; + public double getLastEndDistance() { + return lastEndDistance; } - public void setLastDistance(double lastDistance) { - this.lastDistance = lastDistance; + public void setLastEndDistance(double lastEndDistance) { + this.lastEndDistance = lastEndDistance; } public int getMatchCount() { @@ -153,6 +154,14 @@ public class RoadMatchEntity implements Serializable { this.unMatchPointList = unMatchPointList; } + public double getCurrentLineDistance() { + return currentLineDistance; + } + + public void setCurrentLineDistance(double currentLineDistance) { + this.currentLineDistance = currentLineDistance; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java b/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java index 4bdc105..cd32671 100644 --- a/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java +++ b/app/src/main/java/com/navinfo/outdoor/http/HttpInterface.java @@ -1,9 +1,9 @@ package com.navinfo.outdoor.http; public class HttpInterface { - public static final String IP1 = "http://172.23.138.133:9999/m4";//测试接口 + public static final String IP = "http://172.23.138.133:9999/m4";//测试接口 public static final String IP2 = "http://dtxbmaps.navinfo.com/dtxb/dev/m4";//测试接口-外网 - public static final String IP = "http://dtxbmaps.navinfo.com/dtxb/m4";//正式接口 + public static final String IP1 = "http://dtxbmaps.navinfo.com/dtxb/m4";//正式接口 public static final String USER_PATH = "/user/";//我的 public static final String MSG_LIST_PATH = "/msgList/";//发现 public static final String USER_LOGIN_PATH = "/userlogin/";//登录 diff --git a/app/src/main/res/raw/ding.wav b/app/src/main/res/raw/ding.wav new file mode 100644 index 0000000..cda32b4 Binary files /dev/null and b/app/src/main/res/raw/ding.wav differ