Commit 36877953e89731f6f53cf31874c2552a1b04bf87

Authored by 杨帅
1 parent f561e9e0

1.判断用户是否完成

moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/presenter/RunningMapFragmentPresenter.java
... ... @@ -45,6 +45,8 @@ import com.baidu.trace.api.fence.MonitoredStatusRequest;
45 45 import com.baidu.trace.api.fence.MonitoredStatusResponse;
46 46 import com.baidu.trace.api.fence.OnFenceListener;
47 47 import com.baidu.trace.api.fence.UpdateFenceResponse;
  48 +import com.baidu.trace.api.track.DistanceRequest;
  49 +import com.baidu.trace.api.track.DistanceResponse;
48 50 import com.baidu.trace.api.track.HistoryTrackRequest;
49 51 import com.baidu.trace.api.track.HistoryTrackResponse;
50 52 import com.baidu.trace.api.track.LatestPointResponse;
... ... @@ -83,6 +85,8 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag
83 85 private int realTimePageSize = 1000;
84 86 //分页索引
85 87 private int realTimePageIndex = 1;
  88 + //查询标识
  89 + private int tag = 1;
86 90 /**
87 91 * 历史轨迹请求
88 92 */
... ... @@ -91,6 +95,11 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag
91 95 * 实时轨迹请求
92 96 */
93 97 private LocRequest realTimeListRequest;
  98 +
  99 + /**
  100 + * 创建里程查询请求实例
  101 + */
  102 + private DistanceRequest distanceRequest;
94 103 /**
95 104 * 轨迹点集合
96 105 */
... ... @@ -105,10 +114,9 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag
105 114 * @param endTime
106 115 */
107 116 public void queryHistoryTrace(Context context, String entityName, long startTime, long endTime) {
  117 +
108 118 if (historyTrackRequest == null) {
109   - Log.e(TAG, "queryHistoryTrace: StepService.serviceId" + StepService.serviceId + ",entityName:" + entityName);
110   - Log.e(TAG, "queryHistoryTrace: startTime:" + startTime + ",endTime:" + endTime);
111   - historyTrackRequest = new HistoryTrackRequest(1, StepService.serviceId, entityName);
  119 + historyTrackRequest = new HistoryTrackRequest(tag, StepService.serviceId, entityName);
112 120 //设置查询设备名称
113 121 historyTrackRequest.setEntityName(entityName);
114 122 //历史轨迹开始时间
... ... @@ -141,6 +149,35 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag
141 149 historyTrackRequest.setSupplementMode(SupplementMode.walking);
142 150  
143 151 }
  152 + //创建里程查询
  153 + if (distanceRequest == null) {
  154 + // 创建里程查询请求实例
  155 + distanceRequest = new DistanceRequest(tag, StepService.serviceId, entityName);
  156 + // 设置开始时间
  157 + distanceRequest.setStartTime(startTime);
  158 + // 设置结束时间
  159 + distanceRequest.setEndTime(endTime);
  160 + // 设置需要纠偏
  161 + distanceRequest.setProcessed(true);
  162 +
  163 + // 创建纠偏选项实例
  164 + ProcessOption processOption = new ProcessOption();
  165 + // 设置需要去噪
  166 + processOption.setNeedDenoise(true);
  167 + // 设置需要绑路
  168 + processOption.setNeedMapMatch(false);
  169 + //抽稀:设置是否进行抽稀处理,对冗余的轨迹点进行抽稀去除处理,如一条直线上除起终点外的多个轨迹点
  170 + processOption.setNeedVacuate(true);
  171 + // 设置精度过滤值(定位精度大于100米的过滤掉)
  172 + processOption.setRadiusThreshold(9);
  173 + // 设置交通方式为不行
  174 + processOption.setTransportMode(TransportMode.walking);
  175 + // 设置纠偏选项
  176 + distanceRequest.setProcessOption(processOption);
  177 + // 设置里程填充方式为步行
  178 + distanceRequest.setSupplementMode(SupplementMode.walking);
  179 +
  180 + }
144 181 if (trackPoints == null) {
145 182 trackPoints = new ArrayList<>();
146 183 }
... ... @@ -177,6 +214,7 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter&lt;RunningMapFrag
177 214 for (LatLng latLng : trackPoints) {
178 215 routePoints.add(new RoutePoint(latLng.latitude, latLng.longitude));
179 216 }
  217 + Log.e(TAG, "onHistoryTrackCallback: 轨迹点:"+trackPoints.size()+",详情"+GsonUtil.GsonString(trackPoints) );
180 218 MyMapUtil.drawHistoryTrack(context, getView().baiduMap, trackPoints, SortType.asc, R.color.red, R.drawable.icon_start, R.drawable.icon_end);
181 219 // MyMapUtil.drawMapLineRoutePoint(context, getView().baiduMap, MyMapUtil.optimizePoints(routePoints), R.color.red);
182 220 }
... ... @@ -184,26 +222,17 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter&lt;RunningMapFrag
184 222 }
185 223  
186 224 @Override
187   - public void onLatestPointCallback(LatestPointResponse latestPointResponse) {
188   - super.onLatestPointCallback(latestPointResponse);
189   - Log.e(TAG, "onLatestPointCallback: ");
190   - Toast.makeText(context, "onLatestPointCallback", Toast.LENGTH_SHORT).show();
191   -
192   -// if (StatusCodes.SUCCESS != latestPointResponse.getStatus()) {
193   -// } else {
194   -// Bitmap startPointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), R.drawable.run_map_icon_start), 40, 40);
195   -// OverlayOptions startOptions = new MarkerOptions()
196   -// .position(MyMapUtil.convertTrace2Map(latestPointResponse.getLatestPoint().getLocation())).icon(BitmapDescriptorFactory.fromBitmap(startPointBitmap));
197   -// if (getView() != null) {
198   -// getView().baiduMap.addOverlay(startOptions);
199   -// }
200   -// }
  225 + public void onDistanceCallback(DistanceResponse distanceResponse) {
  226 + super.onDistanceCallback(distanceResponse);
  227 + Toast.makeText(context,"查询的里程数:"+(int)distanceResponse.getDistance()+"米",Toast.LENGTH_SHORT).show();
  228 + Log.e(TAG, "onDistanceCallback: " + distanceResponse.getDistance());
201 229 }
202 230 };
203 231 //开始查询历史轨迹
204 232 if (StepService.mClient != null) {
205 233 StepService.mClient.queryHistoryTrack(historyTrackRequest, historyTrackListener);
206   -
  234 + // 查询里程
  235 + StepService.mClient.queryDistance(distanceRequest, historyTrackListener);
207 236 }
208 237  
209 238 }
... ... @@ -401,7 +430,7 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter&lt;RunningMapFrag
401 430 // }
402 431 // }
403 432  
404   - FenceListRequest request = FenceListRequest.buildServerRequest(1, StepService.serviceId, "yangshuai", null, CoordType.gcj02);
  433 + FenceListRequest request = FenceListRequest.buildServerRequest(tag, StepService.serviceId, "yangshuai", null, CoordType.gcj02);
405 434  
406 435 //发起查询围栏请求
407 436 if (StepService.mClient != null) {
... ... @@ -410,7 +439,7 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter&lt;RunningMapFrag
410 439  
411 440 List<Long> fenid = new ArrayList<>();
412 441 fenid.add(1L);
413   - MonitoredStatusRequest request1 = MonitoredStatusRequest.buildServerRequest(1,
  442 + MonitoredStatusRequest request1 = MonitoredStatusRequest.buildServerRequest(tag,
414 443 StepService.serviceId, "yangshuai", fenid);
415 444 Handler handler = new Handler();
416 445 Runnable runnable = new Runnable() {
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunningMapFragmentView.java
... ... @@ -37,12 +37,14 @@ import com.cnlive.moudle.pedometer.model.RunningMapBean;
37 37 import com.cnlive.moudle.pedometer.ui.fragment.RunningMapFragment;
38 38 import com.cnlive.moudle.pedometer.utils.BitmapUtil;
39 39 import com.cnlive.moudle.pedometer.utils.ButtonAnimUtil;
  40 +import com.cnlive.moudle.pedometer.utils.GsonUtil;
40 41 import com.cnlive.moudle.pedometer.utils.MyMapUtil;
41 42 import com.cnlive.moudle.pedometer.utils.StepUtil;
42 43 import com.example.moudle_pedometer.R;
43 44 import com.hannesdorfmann.mosby3.mvp.MvpView;
44 45  
45 46 import java.util.ArrayList;
  47 +import java.util.HashMap;
46 48 import java.util.List;
47 49  
48 50 public class RunningMapFragmentView implements MvpView, SensorEventListener {
... ... @@ -72,6 +74,10 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener {
72 74 private List<LatLng> trackPoints;
73 75 private Overlay currentLine;
74 76 private List<LatLng> currentPoints;
  77 + private HashMap<Integer, Boolean> importHash;
  78 + List<LatLng> importPoints;
  79 + private String imports = "[{\"latitude\":39.933908761246,\"latitudeE6\":3.9933908761246E7,\"longitude\":116.30882855517,\"longitudeE6\":1.1630882855517E8},{\"latitude\":39.933706935562,\"latitudeE6\":3.9933706935562E7,\"longitude\":116.30881011005,\"longitudeE6\":1.1630881011005001E8},{\"latitude\":39.93371370814,\"latitudeE6\":3.993371370814E7,\"longitude\":116.30872981771,\"longitudeE6\":1.1630872981771E8},{\"latitude\":39.933935049796,\"latitudeE6\":3.9933935049796E7,\"longitude\":116.30861317635,\"longitudeE6\":1.1630861317635E8},{\"latitude\":39.93395837223,\"latitudeE6\":3.993395837223E7,\"longitude\":116.30855458458,\"longitudeE6\":1.1630855458457999E8},{\"latitude\":39.93396326228,\"latitudeE6\":3.993396326228E7,\"longitude\":116.30861833018,\"longitudeE6\":1.1630861833017999E8},{\"latitude\":39.934156956749995,\"latitudeE6\":3.993415695675E7,\"longitude\":116.30869672329999,\"longitudeE6\":1.163086967233E8},{\"latitude\":39.934220163784,\"latitudeE6\":3.9934220163784E7,\"longitude\":116.3087100148,\"longitudeE6\":1.163087100148E8},{\"latitude\":39.934285263072,\"latitudeE6\":3.9934285263072E7,\"longitude\":116.30866498582,\"longitudeE6\":1.1630866498582E8},{\"latitude\":39.934351994321,\"latitudeE6\":3.9934351994320996E7,\"longitude\":116.30865820422,\"longitudeE6\":1.1630865820422E8},{\"latitude\":39.934393506188,\"latitudeE6\":3.9934393506188005E7,\"longitude\":116.3087268324,\"longitudeE6\":1.163087268324E8},{\"latitude\":39.934515310648,\"latitudeE6\":3.9934515310648E7,\"longitude\":116.30877023341,\"longitudeE6\":1.1630877023341E8},{\"latitude\":39.934576888398,\"latitudeE6\":3.9934576888398E7,\"longitude\":116.30876860572,\"longitudeE6\":1.1630876860572E8},{\"latitude\":39.934641987882,\"latitudeE6\":3.9934641987882E7,\"longitude\":116.30872520428,\"longitudeE6\":1.1630872520427999E8},{\"latitude\":39.934720386354,\"latitudeE6\":3.9934720386354E7,\"longitude\":116.30874175083,\"longitudeE6\":1.1630874175083E8},{\"latitude\":39.934703845843,\"latitudeE6\":3.9934703845843E7,\"longitude\":116.30880197017,\"longitudeE6\":1.1630880197016999E8},{\"latitude\":39.934719055573,\"latitudeE6\":3.9934719055573E7,\"longitude\":116.30896553874,\"longitudeE6\":1.1630896553874E8},{\"latitude\":39.93482461107,\"latitudeE6\":3.993482461107E7,\"longitude\":116.30924466304002,\"longitudeE6\":1.1630924466304001E8},{\"latitude\":39.934804821527,\"latitudeE6\":3.9934804821527004E7,\"longitude\":116.30935804892,\"longitudeE6\":1.1630935804892E8},{\"latitude\":39.934856643274,\"latitudeE6\":3.9934856643274E7,\"longitude\":116.30943996874,\"longitudeE6\":1.1630943996874E8},{\"latitude\":39.934844987999,\"latitudeE6\":3.9934844987999E7,\"longitude\":116.30952026112,\"longitudeE6\":1.1630952026112E8},{\"latitude\":39.934722121282,\"latitudeE6\":3.9934722121282004E7,\"longitude\":116.30967542086,\"longitudeE6\":1.1630967542086E8},{\"latitude\":39.934828721701,\"latitudeE6\":3.9934828721701E7,\"longitude\":116.30960516489,\"longitudeE6\":1.1630960516489E8},{\"latitude\":39.934408798988,\"latitudeE6\":3.9934408798988E7,\"longitude\":116.30961357453,\"longitudeE6\":1.1630961357453E8},{\"latitude\":39.934345321571,\"latitudeE6\":3.9934345321571E7,\"longitude\":116.30960842073,\"longitudeE6\":1.1630960842073E8},{\"latitude\":39.93436159016,\"latitudeE6\":3.9934361590160005E7,\"longitude\":116.30954331882,\"longitudeE6\":1.1630954331882E8},{\"latitude\":39.934295133241,\"latitudeE6\":3.9934295133241E7,\"longitude\":116.30957668364,\"longitudeE6\":1.1630957668364E8},{\"latitude\":39.934188525341,\"latitudeE6\":3.9934188525341E7,\"longitude\":116.30958183769,\"longitudeE6\":1.1630958183769001E8},{\"latitude\":39.933976660469,\"latitudeE6\":3.9933976660469E7,\"longitude\":116.30954494693,\"longitudeE6\":1.1630954494693E8},{\"latitude\":39.933993190121,\"latitudeE6\":3.9933993190121E7,\"longitude\":116.30939114375,\"longitudeE6\":1.1630939114375001E8},{\"latitude\":39.933938115564,\"latitudeE6\":3.9933938115563996E7,\"longitude\":116.30932956832,\"longitudeE6\":1.1630932956831999E8},{\"latitude\":39.933916130555,\"latitudeE6\":3.9933916130555E7,\"longitude\":116.30922269279,\"longitudeE6\":1.1630922269279E8},{\"latitude\":39.933836097011,\"latitudeE6\":3.9933836097011E7,\"longitude\":116.30914077307,\"longitudeE6\":1.1630914077307E8}]\n";
  80 + private static int currentIndex = 0;
75 81  
76 82 public RunningMapFragmentView(RunningMapFragment fragment) {
77 83 this.fragment = fragment;
... ... @@ -82,6 +88,19 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener {
82 88 }
83 89  
84 90 public void initView(List<LatLng> trackPoints) {
  91 + importHash = new HashMap<>();
  92 + //打的重要点
  93 + List<LatLng> importPoints = GsonUtil.jsonToList(imports, LatLng.class);
  94 + for (int i = 0; i < importPoints.size(); i++) {
  95 + if (i % 3 != 0) {
  96 + importPoints.remove(i);
  97 + }
  98 + }
  99 + for (int i = 0; i < importPoints.size(); i++) {
  100 + importHash.put(i, false);
  101 + }
  102 +
  103 + Log.e(TAG, "重要点数量: " + importPoints.size());
85 104 currentPoints = new ArrayList<>();
86 105 this.trackPoints = trackPoints;
87 106 this.mMapView = fragment.binding.mapView;
... ... @@ -279,7 +298,7 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener {
279 298 fragment.binding.tvGpsPopBg.setVisibility(View.GONE);
280 299 }
281 300 //设置图标
282   - if (fragment.binding.ivGpsState.getTag()== null || !"GPS_ACCURACY_MID".equals(fragment.binding.ivGpsState.getTag().toString())) {
  301 + if (fragment.binding.ivGpsState.getTag() == null || !"GPS_ACCURACY_MID".equals(fragment.binding.ivGpsState.getTag().toString())) {
283 302 fragment.binding.ivGpsState.setTag("GPS_ACCURACY_MID");
284 303 fragment.binding.ivGpsState.setBackground(getContext().getResources().getDrawable(R.drawable.rt_training_gps_2));
285 304 }
... ... @@ -345,6 +364,18 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener {
345 364 }
346 365 currentLine = MyMapUtil.drawMapLine(getContext(), baiduMap, currentPoints, R.color.red);
347 366 }
  367 +
  368 + //开始比较
  369 + if (currentIndex < importPoints.size()) {
  370 + LatLng curLatLng = new LatLng(location.getLatitude(),
  371 + location.getLongitude());
  372 + LatLng importLatLng = importPoints.get(currentIndex);
  373 + if (DistanceUtil.getDistance(importLatLng, curLatLng) < 50) {
  374 + importHash.put(currentIndex, true);
  375 + currentIndex++;
  376 + Toast.makeText(getContext(), "开始比较第" + currentIndex + "个点", Toast.LENGTH_SHORT).show();
  377 + }
  378 + }
348 379 }
349 380 myCurLatLng = new LatLng(location.getLatitude(),
350 381 location.getLongitude());
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/fragment/RunningMapFragment.java
... ... @@ -97,6 +97,7 @@ public class RunningMapFragment extends QMUIFragment&lt;RunningMapFragmentView, Run
97 97 //初始化提示框
98 98 initTipDialog();
99 99 List<LatLng> trackPoints = GsonUtil.jsonToList(test, LatLng.class);
  100 +
100 101 if (getArguments() != null) {
101 102 runningMapBean = (RunningMapBean) getArguments().getSerializable("runningMapBean");
102 103 }
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/MyMapUtil.java
... ... @@ -44,7 +44,7 @@ public class MyMapUtil {
44 44 //只有一个点
45 45 if (points.size() == 1) {
46 46 if (startIconRes != 0) {
47   - Bitmap pointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), startIconRes), 40, 40);
  47 + Bitmap pointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), startIconRes), 24, 30);
48 48 OverlayOptions startOptions = new MarkerOptions().position(points.get(0)).icon(BitmapDescriptorFactory.fromBitmap(pointBitmap));
49 49 // .zIndex(9).draggable(true);
50 50 return baiduMap.addOverlay(startOptions);
... ... @@ -67,7 +67,7 @@ public class MyMapUtil {
67 67 Bitmap startPointBitmap = null;
68 68 OverlayOptions startOptions = null;
69 69 if (startIconRes != 0) {
70   - startPointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), startIconRes), 40, 40);
  70 + startPointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), startIconRes), 24, 30);
71 71 startOptions = new MarkerOptions().perspective(false).animateType(MarkerOptions.MarkerAnimateType.grow)
72 72 .position(startPoint).icon(BitmapDescriptorFactory.fromBitmap(startPointBitmap));
73 73 }
... ... @@ -76,7 +76,7 @@ public class MyMapUtil {
76 76 Bitmap endPointBitmap = null;
77 77 OverlayOptions endOptions = null;
78 78 if (endIconRes != 0) {
79   - endPointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), endIconRes), 40, 40);
  79 + endPointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), endIconRes), 24, 30);
80 80 endOptions = new MarkerOptions().position(endPoint).perspective(false).animateType(MarkerOptions.MarkerAnimateType.grow)
81 81 .icon(BitmapDescriptorFactory.fromBitmap(endPointBitmap));
82 82 }
... ...