Commit feca720b133d6d2721d8b51bdc2cb5e5cab0bb08
Merge branch 'master' of bj.gitlab.cnlive.com:cnlive-team/ModulePedometer
Showing
30 changed files
with
579 additions
and
227 deletions
config.gradle
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/presenter/CollRunningFinishFragmetPresenter.java
| ... | ... | @@ -43,10 +43,13 @@ import io.reactivex.disposables.Disposable; |
| 43 | 43 | public class CollRunningFinishFragmetPresenter extends MvpBasePresenter<CollRunningFinishFragmentView> { |
| 44 | 44 | |
| 45 | 45 | public void uploadTraceDateToServer(Activity context, CollUserStepEntity userStepEntity, String roadmap) { |
| 46 | + if (null == getView()) { | |
| 47 | + return; | |
| 48 | + } | |
| 46 | 49 | if (null != getView()) { |
| 47 | 50 | getView().limitUploadBtnTouch(); |
| 48 | 51 | } |
| 49 | - QMUITipDialogUtil.loadingDialog(context, "正在上传数据", false); | |
| 52 | + getView().showLoading("正在上传数据"); | |
| 50 | 53 | Map<String, String> paramsMap = new HashMap<>(); |
| 51 | 54 | //赛事id |
| 52 | 55 | if (!TextUtils.isEmpty(userStepEntity.getStreetId())) { |
| ... | ... | @@ -120,6 +123,7 @@ public class CollRunningFinishFragmetPresenter extends MvpBasePresenter<CollRunn |
| 120 | 123 | if (getView() == null) { |
| 121 | 124 | return; |
| 122 | 125 | } |
| 126 | + getView().hideLoading(); | |
| 123 | 127 | if (null != getView()) { |
| 124 | 128 | getView().allowUploadBtnTouch(); |
| 125 | 129 | } |
| ... | ... | @@ -132,7 +136,7 @@ public class CollRunningFinishFragmetPresenter extends MvpBasePresenter<CollRunn |
| 132 | 136 | }, "重试", new SelectDialog.DialogInterface() { |
| 133 | 137 | @Override |
| 134 | 138 | public void onClick(SelectDialog dialog) { |
| 135 | - dialog.dismiss(); | |
| 139 | + getView().hideLoading(); | |
| 136 | 140 | uploadTraceDateToServer(context, userStepEntity, roadmap); |
| 137 | 141 | } |
| 138 | 142 | }); |
| ... | ... | @@ -149,7 +153,7 @@ public class CollRunningFinishFragmetPresenter extends MvpBasePresenter<CollRunn |
| 149 | 153 | return; |
| 150 | 154 | } |
| 151 | 155 | EventBus.getDefault().post(new MessageEvent(Constant.UPDATA_COLL_TRACE_LIST, "")); |
| 152 | - QMUITipDialogUtil.dismessDialog(); | |
| 156 | + getView().hideLoading(); | |
| 153 | 157 | QMUITipDialogUtil.successDialog(context, "数据上传成功", 1); |
| 154 | 158 | //清空数据 |
| 155 | 159 | CollStepUtil.clearRunData(context, CollCommonInfo.getUserId(context)); | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/presenter/CollRunningMapFragmentPresenter.java
| ... | ... | @@ -140,7 +140,7 @@ public class CollRunningMapFragmentPresenter extends MvpBasePresenter<CollRunnin |
| 140 | 140 | //自动判断交通方式 |
| 141 | 141 | processOption.setTransportMode(TransportMode.walking); |
| 142 | 142 | // 设置精度过滤值(定位精度大于100米的过滤掉) |
| 143 | - processOption.setRadiusThreshold(9); | |
| 143 | + processOption.setRadiusThreshold(20); | |
| 144 | 144 | // 设置纠偏选项 |
| 145 | 145 | historyTrackRequest.setProcessOption(processOption); |
| 146 | 146 | // 设置里程填充方式为驾车 |
| ... | ... | @@ -208,7 +208,6 @@ public class CollRunningMapFragmentPresenter extends MvpBasePresenter<CollRunnin |
| 208 | 208 | queryHistoryTrace(context, entityName, startTime, endTime); |
| 209 | 209 | } else { |
| 210 | 210 | if (getView() != null) { |
| 211 | - | |
| 212 | 211 | //开始比较(杨帅的思路) |
| 213 | 212 | // for (int i = 0; i < trackPoints.size(); i++) { |
| 214 | 213 | // if (matchIndex < importPoints.size() - 1) { |
| ... | ... | @@ -236,34 +235,14 @@ public class CollRunningMapFragmentPresenter extends MvpBasePresenter<CollRunnin |
| 236 | 235 | // } else { |
| 237 | 236 | // Toast.makeText(context, "已完成", Toast.LENGTH_LONG).show(); |
| 238 | 237 | // } |
| 239 | - //郭瑞鹏的思路 | |
| 240 | - int index = 0; | |
| 241 | - for (int i = 0; i < importPoints.size(); i++) { | |
| 242 | - LatLng importLatLng = importPoints.get(i); | |
| 243 | - for (int j = index; j < trackPoints.size(); j++) { | |
| 244 | - double distance = DistanceUtil.getDistance(importLatLng, trackPoints.get(j)); | |
| 245 | - if (distance<100){ | |
| 246 | - importHash.put(i,true); | |
| 247 | - index=j; | |
| 248 | - } | |
| 249 | - } | |
| 250 | - } | |
| 251 | - //输出 | |
| 252 | - int result = 0; | |
| 253 | - for (int i = 0; i < importHash.size(); i++) { | |
| 254 | - if (!importHash.get(i)) { | |
| 255 | - result++; | |
| 256 | - Log.e(TAG, "onHistoryTrackCallback: 没过:" + i + importHash.get(i)); | |
| 257 | - } | |
| 258 | - } | |
| 259 | - if (result > importPoints.size() * 0.4) { | |
| 260 | - Toast.makeText(context, "没有完成", Toast.LENGTH_LONG).show(); | |
| 261 | - | |
| 262 | - } else { | |
| 263 | - Toast.makeText(context, "已完成", Toast.LENGTH_LONG).show(); | |
| 264 | - } | |
| 265 | - Log.e(TAG, "结果: " + result); | |
| 266 | - Log.e(TAG, "onHistoryTrackCallback: 轨迹点:" + trackPoints.size() + ",详情" + GsonUtil.GsonString(trackPoints)); | |
| 238 | +// if (result > importPoints.size() * 0.4) { | |
| 239 | +// Toast.makeText(context, "没有完成", Toast.LENGTH_LONG).show(); | |
| 240 | +// | |
| 241 | +// } else { | |
| 242 | +// Toast.makeText(context, "已完成", Toast.LENGTH_LONG).show(); | |
| 243 | +// } | |
| 244 | +// Log.e(TAG, "结果: " + result); | |
| 245 | +// Log.e(TAG, "onHistoryTrackCallback: 轨迹点:" + trackPoints.size() + ",详情" + GsonUtil.GsonString(trackPoints)); | |
| 267 | 246 | MyMapUtil.drawHistoryTrack(context, getView().baiduMap, trackPoints, SortType.asc, R.color.red, R.drawable.icon_start, R.drawable.icon_end); |
| 268 | 247 | // MyMapUtil.drawMapLineRoutePoint(context, getView().baiduMap, MyMapUtil.optimizePoints(routePoints), R.color.red); |
| 269 | 248 | } |
| ... | ... | @@ -274,7 +253,7 @@ public class CollRunningMapFragmentPresenter extends MvpBasePresenter<CollRunnin |
| 274 | 253 | public void onDistanceCallback(DistanceResponse distanceResponse) { |
| 275 | 254 | super.onDistanceCallback(distanceResponse); |
| 276 | 255 | // Toast.makeText(context, "查询的里程数:" + (int) distanceResponse.getDistance() + "米", Toast.LENGTH_SHORT).show(); |
| 277 | - Log.e(TAG, "onDistanceCallback: " + distanceResponse.getDistance()); | |
| 256 | +// Log.e(TAG, "onDistanceCallback: " + distanceResponse.getDistance()); | |
| 278 | 257 | } |
| 279 | 258 | }; |
| 280 | 259 | //开始查询历史轨迹 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/view/CollRunRaceDetailFragmentView.java
| ... | ... | @@ -669,7 +669,7 @@ public class CollRunRaceDetailFragmentView implements MvpView, SensorEventListen |
| 669 | 669 | if (isFirstLoc) { |
| 670 | 670 | isFirstLoc = false; |
| 671 | 671 | if (location.getRadius() > Constant.LOCA_ACCURACY) { |
| 672 | - Toast.makeText(getContext(), "当前定位误差为:" + location.getRadius() + "米,请您移动至空旷地带!", Toast.LENGTH_SHORT).show(); | |
| 672 | + Toast.makeText(getContext(), "当前定位误差为:" + (int)location.getRadius() + "米,请您移动至空旷地带!", Toast.LENGTH_SHORT).show(); | |
| 673 | 673 | } |
| 674 | 674 | } else { |
| 675 | 675 | //过滤定位精度 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/view/CollRunningFinishFragmentView.java
| ... | ... | @@ -8,6 +8,7 @@ import android.text.TextUtils; |
| 8 | 8 | import android.util.Log; |
| 9 | 9 | import android.view.MotionEvent; |
| 10 | 10 | import android.view.View; |
| 11 | +import android.widget.TextView; | |
| 11 | 12 | |
| 12 | 13 | import com.baidu.mapapi.map.BaiduMap; |
| 13 | 14 | import com.baidu.mapapi.map.MapView; |
| ... | ... | @@ -122,7 +123,7 @@ public class CollRunningFinishFragmentView implements MvpView, OnFenceListener { |
| 122 | 123 | String faceUrl = CommonInfo.getUserIcon(getContext()); |
| 123 | 124 | if (!TextUtils.isEmpty(faceUrl)) { |
| 124 | 125 | GlideApp.with(getContext()).load(faceUrl).into(fragment.binding.includeFinishUserInfo.qmIvIcon); |
| 125 | - }else { | |
| 126 | + } else { | |
| 126 | 127 | GlideApp.with(getContext()).load(getContext().getResources().getString(R.string.default_face_url)).into(fragment.binding.includeFinishUserInfo.qmIvIcon); |
| 127 | 128 | } |
| 128 | 129 | //设置标题 |
| ... | ... | @@ -207,7 +208,7 @@ public class CollRunningFinishFragmentView implements MvpView, OnFenceListener { |
| 207 | 208 | } |
| 208 | 209 | } |
| 209 | 210 | dialog.dismiss(); |
| 210 | - QMUITipDialogUtil.loadingDialog(getContext(), "正在截取赛事图片,请稍后", false); | |
| 211 | + showLoading("正在截取赛事图片,请稍后"); | |
| 211 | 212 | //延迟一秒进行截图,以免把打的点都截取到 |
| 212 | 213 | new Handler().postDelayed(new Runnable() { |
| 213 | 214 | @Override |
| ... | ... | @@ -358,8 +359,8 @@ public class CollRunningFinishFragmentView implements MvpView, OnFenceListener { |
| 358 | 359 | baiduMap.snapshot(new BaiduMap.SnapshotReadyCallback() { |
| 359 | 360 | @Override |
| 360 | 361 | public void onSnapshotReady(Bitmap bitmap) { |
| 361 | - QMUITipDialogUtil.dismessDialog(); | |
| 362 | 362 | if (null == bitmap) { |
| 363 | + hideLoading(); | |
| 363 | 364 | QMUITipDialogUtil.failedDialog(getContext(), "赛事图片截取失败,请重试", 2); |
| 364 | 365 | return; |
| 365 | 366 | } |
| ... | ... | @@ -376,7 +377,7 @@ public class CollRunningFinishFragmentView implements MvpView, OnFenceListener { |
| 376 | 377 | //开始上传 |
| 377 | 378 | uploadRoadMapPic(roadMapPath); |
| 378 | 379 | } catch (Exception e) { |
| 379 | - QMUITipDialogUtil.dismessDialog(); | |
| 380 | + hideLoading(); | |
| 380 | 381 | QMUITipDialogUtil.failedDialog(getContext(), "赛事图片截取失败,请重试", 2); |
| 381 | 382 | //允许点击 |
| 382 | 383 | allowUploadBtnTouch(); |
| ... | ... | @@ -395,14 +396,14 @@ public class CollRunningFinishFragmentView implements MvpView, OnFenceListener { |
| 395 | 396 | //禁止点击 |
| 396 | 397 | limitUploadBtnTouch(); |
| 397 | 398 | if (!TextUtils.isEmpty(roadMapPath)) { |
| 398 | - QMUITipDialogUtil.loadingDialog(getContext(), "正在上传赛事图片,请稍后", false); | |
| 399 | + showLoading("正在上传赛事图片,请稍后"); | |
| 399 | 400 | List<String> imagePaths = new ArrayList<>(); |
| 400 | 401 | imagePaths.add(roadMapPath); |
| 401 | 402 | UploadLogic.uploadAddressPicInfo(getContext(), imagePaths, new Event<String>() |
| 402 | 403 | .setFailureCallback(new FailureCallback() { |
| 403 | 404 | @Override |
| 404 | 405 | public void onFailure(int i, String s) { |
| 405 | - QMUITipDialogUtil.dismessDialog(); | |
| 406 | + hideLoading(); | |
| 406 | 407 | SelectDialog selectDialog = new SelectDialog(getContext(), "赛事图片上传失败,是否重试?", "取消", new SelectDialog.DialogInterface() { |
| 407 | 408 | @Override |
| 408 | 409 | public void onClick(SelectDialog dialog) { |
| ... | ... | @@ -428,7 +429,7 @@ public class CollRunningFinishFragmentView implements MvpView, OnFenceListener { |
| 428 | 429 | .setSuccessCallback(new SuccessCallback<String>() { |
| 429 | 430 | @Override |
| 430 | 431 | public void onSuccess(String data) { |
| 431 | - QMUITipDialogUtil.dismessDialog(); | |
| 432 | + hideLoading(); | |
| 432 | 433 | //开始把数据传到服务端 |
| 433 | 434 | collUserStepEntity = CollStepUtil.getCollUserStepData(getContext(), CollCommonInfo.getUserId(getContext())); |
| 434 | 435 | if (null != fragment.getPresenter() || null == fragment.getActivity() || null == collUserStepEntity || TextUtils.isEmpty(data)) { |
| ... | ... | @@ -441,6 +442,26 @@ public class CollRunningFinishFragmentView implements MvpView, OnFenceListener { |
| 441 | 442 | } |
| 442 | 443 | } |
| 443 | 444 | |
| 445 | + public void showLoading(String tip) { | |
| 446 | + if (null == getContext() || null == fragment.binding.llLoading || null == fragment.binding.tvLoadingTip) { | |
| 447 | + return; | |
| 448 | + } | |
| 449 | + if (fragment.binding.llLoading.getVisibility() == View.GONE) { | |
| 450 | + fragment.binding.llLoading.setVisibility(View.VISIBLE); | |
| 451 | + } | |
| 452 | + if (!TextUtils.isEmpty(tip)) { | |
| 453 | + fragment.binding.tvLoadingTip.setText(tip); | |
| 454 | + } | |
| 455 | + | |
| 456 | + } | |
| 457 | + public void hideLoading() { | |
| 458 | + if (null == getContext() || null == fragment.binding.llLoading || null == fragment.binding.tvLoadingTip) { | |
| 459 | + return; | |
| 460 | + } | |
| 461 | + if (fragment.binding.llLoading.getVisibility() == View.VISIBLE) { | |
| 462 | + fragment.binding.llLoading.setVisibility(View.GONE); | |
| 463 | + } | |
| 464 | + } | |
| 444 | 465 | |
| 445 | 466 | public void initMap() { |
| 446 | 467 | this.mMapView = fragment.binding.mapView; | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/view/CollRunningMapFragmentView.java
| ... | ... | @@ -36,6 +36,7 @@ import com.baidu.mapapi.utils.DistanceUtil; |
| 36 | 36 | import com.baidu.trace.model.SortType; |
| 37 | 37 | import com.cnlive.libs.base.util.AlertUtil; |
| 38 | 38 | import com.cnlive.moudle.collectionTrace.model.CollectPoint; |
| 39 | +import com.cnlive.moudle.collectionTrace.service.CollKeepLiveService; | |
| 39 | 40 | import com.cnlive.moudle.collectionTrace.service.CollStepService; |
| 40 | 41 | import com.cnlive.moudle.collectionTrace.ui.activity.CollRunningFinishActivity; |
| 41 | 42 | import com.cnlive.moudle.collectionTrace.ui.fragment.CollRunningMapFragment; |
| ... | ... | @@ -303,7 +304,7 @@ public class CollRunningMapFragmentView implements MvpView, SensorEventListener |
| 303 | 304 | public void onClick(View view) { |
| 304 | 305 | //先获取打点数量 |
| 305 | 306 | int canTakePointCount = CollStepUtil.getCollImportPointSize(getContext(), CollCommonInfo.getUserId(getContext())); |
| 306 | - if (canTakePointCount<2) { | |
| 307 | + if (canTakePointCount < 2) { | |
| 307 | 308 | AlertUtil.showDeftToast(getContext(), "请至少打两个点后结束"); |
| 308 | 309 | } else { |
| 309 | 310 | if (null != followMyLocation) { |
| ... | ... | @@ -444,12 +445,15 @@ public class CollRunningMapFragmentView implements MvpView, SensorEventListener |
| 444 | 445 | private void stopStepService() { |
| 445 | 446 | CollCommonInfo.setTsRunBaiduTraceService(getContext(), false); |
| 446 | 447 | CollCommonInfo.setIsRunKeepAliveService(getContext(), false); |
| 448 | + CollCommonInfo.setIsRunStepService(getContext(), false); | |
| 447 | 449 | CollCommonInfo.setIsWriteUserStep(getContext(), false); |
| 448 | 450 | CollCommonInfo.setIsFirstStepSendTraceTip(getContext(), true); |
| 449 | 451 | if (CollStepService.mClient != null) { |
| 450 | 452 | CollStepService.mClient.stopGather(StepService.traceListener); |
| 451 | 453 | } |
| 454 | + fragment.getActivity().stopService(new Intent(fragment.getActivity(), CollKeepLiveService.class)); | |
| 452 | 455 | fragment.getActivity().stopService(new Intent(fragment.getActivity(), CollStepService.class)); |
| 456 | + | |
| 453 | 457 | } |
| 454 | 458 | |
| 455 | 459 | private void initChrom() { |
| ... | ... | @@ -561,7 +565,7 @@ public class CollRunningMapFragmentView implements MvpView, SensorEventListener |
| 561 | 565 | //minTimeInterval - 最短定位时间间隔,单位毫秒,最小值0,开发者可以在设置希望的位置回调最短时间间隔 |
| 562 | 566 | //minDistance - 最短定位距离间隔,单位米,最小值0,开发者可以设置希望的位置回调距离间隔 |
| 563 | 567 | //locSensitivity - 定位变化敏感程度,LOC_SENSITIVITY_HIGHT,LOC_SENSITIVITY_MIDDLE,LOC_SENSITIVITY_LOW |
| 564 | - option.setOpenAutoNotifyMode(3000, 1, LocationClientOption.LOC_SENSITIVITY_HIGHT); | |
| 568 | +// option.setOpenAutoNotifyMode(3000, 1, LocationClientOption.LOC_SENSITIVITY_HIGHT); | |
| 565 | 569 | //可选,定位SDK内部是一个service,并放到了独立进程。 |
| 566 | 570 | //设置是否在stop的时候杀死这个进程,默认(建议)不杀死,即setIgnoreKillProcess(true) |
| 567 | 571 | option.setIgnoreKillProcess(true); | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/view/CollTraceListDetailFragmentView.java
| ... | ... | @@ -4,6 +4,7 @@ import android.app.Activity; |
| 4 | 4 | import android.content.Context; |
| 5 | 5 | import android.graphics.Bitmap; |
| 6 | 6 | import android.graphics.BitmapFactory; |
| 7 | +import android.graphics.Point; | |
| 7 | 8 | import android.os.Handler; |
| 8 | 9 | import android.support.v7.widget.LinearLayoutManager; |
| 9 | 10 | import android.text.TextUtils; |
| ... | ... | @@ -12,6 +13,8 @@ import android.view.MotionEvent; |
| 12 | 13 | import android.view.View; |
| 13 | 14 | |
| 14 | 15 | import com.baidu.mapapi.map.BaiduMap; |
| 16 | +import com.baidu.mapapi.map.MapStatus; | |
| 17 | +import com.baidu.mapapi.map.MapStatusUpdateFactory; | |
| 15 | 18 | import com.baidu.mapapi.map.MapView; |
| 16 | 19 | import com.baidu.mapapi.map.Overlay; |
| 17 | 20 | import com.baidu.mapapi.map.UiSettings; |
| ... | ... | @@ -298,7 +301,15 @@ public class CollTraceListDetailFragmentView implements MvpView, OnFenceListener |
| 298 | 301 | } |
| 299 | 302 | |
| 300 | 303 | } |
| 301 | - // | |
| 304 | + //设置显示位置 | |
| 305 | + if (null != getContext()) { | |
| 306 | + MapStatus.Builder builder = new MapStatus.Builder(); | |
| 307 | + Point screenPoint = ScreenUtil.getScreenPoint(getContext()); | |
| 308 | + if (null != screenPoint) { | |
| 309 | + builder.targetScreen(new Point(screenPoint.x / 2, screenPoint.y / 3)); | |
| 310 | + } | |
| 311 | + baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); | |
| 312 | + } | |
| 302 | 313 | } |
| 303 | 314 | } |
| 304 | 315 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/view/StartTraceFragmentView.java
| ... | ... | @@ -133,6 +133,9 @@ public class StartTraceFragmentView implements MvpView, SensorEventListener { |
| 133 | 133 | MyMapUtil.getGeoCoderResult(new LatLng(followMyLocation.latitude, followMyLocation.longitude), new MyMapUtil.GeoCodeResult() { |
| 134 | 134 | @Override |
| 135 | 135 | public void success(String address) { |
| 136 | + if (null==getContext()){ | |
| 137 | + return; | |
| 138 | + } | |
| 136 | 139 | QMUITipDialogUtil.dismessDialog(); |
| 137 | 140 | if (null != address && !TextUtils.isEmpty(address)) { |
| 138 | 141 | currentAddress = address; |
| ... | ... | @@ -301,9 +304,8 @@ public class StartTraceFragmentView implements MvpView, SensorEventListener { |
| 301 | 304 | if (CollStepService.mClient != null) { |
| 302 | 305 | CollStepService.mClient.stopGather(CollStepService.traceListener); |
| 303 | 306 | } |
| 304 | - fragment.getActivity().stopService(new Intent(fragment.getActivity(), CollStepService.class)); | |
| 305 | 307 | fragment.getActivity().stopService(new Intent(fragment.getActivity(), CollKeepLiveService.class)); |
| 306 | - | |
| 308 | + fragment.getActivity().stopService(new Intent(fragment.getActivity(), CollStepService.class)); | |
| 307 | 309 | } |
| 308 | 310 | |
| 309 | 311 | /** |
| ... | ... | @@ -358,7 +360,8 @@ public class StartTraceFragmentView implements MvpView, SensorEventListener { |
| 358 | 360 | //可选,设置是否需要设备方向结果 |
| 359 | 361 | option.setNeedDeviceDirect(false); |
| 360 | 362 | //设置打开自动回调位置模式,该开关打开后,期间只要定位SDK检测到位置变化就会主动回调给开发者 |
| 361 | - option.setOpenAutoNotifyMode(3000, 1, LocationClientOption.LOC_SENSITIVITY_HIGHT); | |
| 363 | +// option.setOpenAutoNotifyMode(3000, 1, LocationClientOption.LOC_SENSITIVITY_HIGHT); | |
| 364 | + option.setOpenAutoNotifyMode(); | |
| 362 | 365 | mLocClient.setLocOption(option); |
| 363 | 366 | mLocClient.start(); |
| 364 | 367 | //设置地图加载完毕监听 |
| ... | ... | @@ -429,7 +432,7 @@ public class StartTraceFragmentView implements MvpView, SensorEventListener { |
| 429 | 432 | } |
| 430 | 433 | if (isFirstLoc) { |
| 431 | 434 | isFirstLoc = false; |
| 432 | - Toast.makeText(getContext(), "当前定位误差为:" + location.getRadius() + "米,请您移动至空旷地带!", Toast.LENGTH_SHORT).show(); | |
| 435 | + Toast.makeText(getContext(), "当前定位误差为:" + (int)location.getRadius() + "米,请您移动至空旷地带!", Toast.LENGTH_SHORT).show(); | |
| 433 | 436 | //过滤定位精度 |
| 434 | 437 | if (location.getRadius() > Constant.LOCA_ACCURACY) { |
| 435 | 438 | return; | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/service/CollKeepLiveService.java
| ... | ... | @@ -44,7 +44,7 @@ public class CollKeepLiveService extends Service implements MediaPlayer.OnComple |
| 44 | 44 | private NotificationManager mNM; |
| 45 | 45 | private Notification notification = null; |
| 46 | 46 | //是否在后台运行 |
| 47 | - public static boolean isKeepService = true; | |
| 47 | + public static boolean isKeepService = false; | |
| 48 | 48 | public static CollKeepLiveService instance; |
| 49 | 49 | private final String TAG = "CollKeepLiveService"; |
| 50 | 50 | private Handler handler; |
| ... | ... | @@ -152,8 +152,20 @@ public class CollKeepLiveService extends Service implements MediaPlayer.OnComple |
| 152 | 152 | if (isRun) { |
| 153 | 153 | showHideForegroundNotification(); |
| 154 | 154 | startPlaySong(); |
| 155 | - if (runnable != null) { | |
| 156 | - handler.postDelayed(runnable, 5000); | |
| 155 | +// if (runnable != null) { | |
| 156 | +// handler.postDelayed(runnable, 5000); | |
| 157 | +// } | |
| 158 | + } else { | |
| 159 | + try { | |
| 160 | + if (myReceiver != null && isRegisterReceiver) { | |
| 161 | + unregisterReceiver(myReceiver); | |
| 162 | + } | |
| 163 | + } catch (Exception e) { | |
| 164 | + Log.e(TAG, "run: "); | |
| 165 | + } | |
| 166 | + stopPlaySong(); | |
| 167 | + if (isStartForegroundService) { | |
| 168 | + stopForeground(true); | |
| 157 | 169 | } |
| 158 | 170 | } |
| 159 | 171 | return START_STICKY; |
| ... | ... | @@ -207,9 +219,9 @@ public class CollKeepLiveService extends Service implements MediaPlayer.OnComple |
| 207 | 219 | channel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PRIVATE); |
| 208 | 220 | mNM.createNotificationChannel(channel); |
| 209 | 221 | } |
| 210 | - Intent notificationIntent = new Intent(this, CollRunningMapActivity.class); | |
| 222 | +// Intent notificationIntent = new Intent(this, CollRunningMapActivity.class); | |
| 211 | 223 | notification = new NotificationCompat.Builder(this, CHANNEL_ONE_ID) |
| 212 | - .setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0)) | |
| 224 | +// .setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0)) | |
| 213 | 225 | .setSmallIcon(R.mipmap.ic_launcher) |
| 214 | 226 | // .setCustomContentView(remoteViews) |
| 215 | 227 | .setContentTitle(getResources().getString(R.string.app_name)) |
| ... | ... | @@ -279,11 +291,11 @@ public class CollKeepLiveService extends Service implements MediaPlayer.OnComple |
| 279 | 291 | if (isRun) { |
| 280 | 292 | Log.e(TAG, "重新播放"); |
| 281 | 293 | mediaPlayer.start(); |
| 282 | - Intent intent = new Intent("com.cnlive.strike.receiver.CollServiceReceiver"); | |
| 283 | - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
| 284 | - intent.setComponent(new ComponentName(getPackageName(), "com.cnlive.strike.receiver.CollServiceReceiver"));//高版本Android发送广播需要加这句 | |
| 285 | - } | |
| 286 | - sendBroadcast(intent); | |
| 294 | +// Intent intent = new Intent("com.cnlive.strike.receiver.CollServiceReceiver"); | |
| 295 | +// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
| 296 | +// intent.setComponent(new ComponentName(getPackageName(), "com.cnlive.strike.receiver.CollServiceReceiver"));//高版本Android发送广播需要加这句 | |
| 297 | +// } | |
| 298 | +// sendBroadcast(intent); | |
| 287 | 299 | } else { |
| 288 | 300 | Log.e(TAG, "停止重新播放"); |
| 289 | 301 | stopPlaySong(); | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/service/CollStepService.java
| ... | ... | @@ -439,9 +439,9 @@ public class CollStepService extends Service implements SensorEventListener { |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | |
| 442 | - Intent notificationIntent = new Intent(this, CollRunningMapActivity.class); | |
| 442 | +// Intent notificationIntent = new Intent(this, CollRunningMapActivity.class); | |
| 443 | 443 | notification = new NotificationCompat.Builder(this, CHANNEL_ONE_ID) |
| 444 | - .setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0)) | |
| 444 | +// .setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0)) | |
| 445 | 445 | .setSmallIcon(R.mipmap.ic_launcher) |
| 446 | 446 | // .setCustomContentView(remoteViews) |
| 447 | 447 | .setContentTitle(getResources().getString(R.string.app_name)) |
| ... | ... | @@ -721,10 +721,10 @@ public class CollStepService extends Service implements SensorEventListener { |
| 721 | 721 | * 监听晚上0点变化初始化数据 |
| 722 | 722 | */ |
| 723 | 723 | private void isNewDay() { |
| 724 | - String time = "00:00"; | |
| 725 | - if (time.equals(new SimpleDateFormat("HH:mm").format(new Date())) || !CURRENT_DATE.equals(getTodayDate())) { | |
| 726 | - initTodayData(userId); | |
| 727 | - } | |
| 724 | +// String time = "00:00"; | |
| 725 | +// if (time.equals(new SimpleDateFormat("HH:mm").format(new Date())) || !CURRENT_DATE.equals(getTodayDate())) { | |
| 726 | +// initTodayData(userId); | |
| 727 | +// } | |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | // /** | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/presenter/ALLScoreDetailFragmentPresenter.java
| 1 | 1 | package com.cnlive.moudle.pedometer.frame.presenter; |
| 2 | 2 | |
| 3 | 3 | import android.app.Activity; |
| 4 | +import android.graphics.Point; | |
| 4 | 5 | import android.text.TextUtils; |
| 5 | 6 | import android.widget.Toast; |
| 6 | 7 | |
| 8 | +import com.baidu.mapapi.map.MapStatus; | |
| 9 | +import com.baidu.mapapi.map.MapStatusUpdate; | |
| 10 | +import com.baidu.mapapi.map.MapStatusUpdateFactory; | |
| 7 | 11 | import com.baidu.mapapi.model.LatLng; |
| 8 | 12 | import com.baidu.trace.LBSTraceClient; |
| 9 | 13 | import com.baidu.trace.model.SortType; |
| ... | ... | @@ -16,6 +20,7 @@ import com.cnlive.moudle.pedometer.ui.widget.SelectDialog; |
| 16 | 20 | import com.cnlive.moudle.pedometer.utils.GsonUtil; |
| 17 | 21 | import com.cnlive.moudle.pedometer.utils.MyMapUtil; |
| 18 | 22 | import com.cnlive.moudle.pedometer.utils.QMUITipDialogUtil; |
| 23 | +import com.cnlive.moudle.pedometer.utils.ScreenUtil; | |
| 19 | 24 | import com.example.moudle_pedometer.R; |
| 20 | 25 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; |
| 21 | 26 | |
| ... | ... | @@ -77,7 +82,15 @@ public class ALLScoreDetailFragmentPresenter extends MvpBasePresenter<ALLScoreDe |
| 77 | 82 | MyMapUtil.setMapAutoZoom(getView().baiduMap, resultPoints, -0.8f); |
| 78 | 83 | } |
| 79 | 84 | } |
| 80 | - | |
| 85 | + //设置显示位置 | |
| 86 | + if (null != getView()) { | |
| 87 | + MapStatus.Builder builder = new MapStatus.Builder(); | |
| 88 | + Point screenPoint = ScreenUtil.getScreenPoint(context); | |
| 89 | + if (null != screenPoint) { | |
| 90 | + builder.targetScreen(new Point(screenPoint.x / 2, screenPoint.y / 3)); | |
| 91 | + } | |
| 92 | + getView().baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); | |
| 93 | + } | |
| 81 | 94 | } |
| 82 | 95 | //如果用户点击暂停按钮,进行分段查询 |
| 83 | 96 | if (runningFinishBean.isPause()) { |
| ... | ... | @@ -98,6 +111,15 @@ public class ALLScoreDetailFragmentPresenter extends MvpBasePresenter<ALLScoreDe |
| 98 | 111 | //设置地图自动缩放 |
| 99 | 112 | allResultList.addAll(resultPoints); |
| 100 | 113 | MyMapUtil.setMapAutoZoom(getView().baiduMap, allResultList, -0.8f); |
| 114 | + //设置显示位置 | |
| 115 | + if (null != getView()) { | |
| 116 | + MapStatus.Builder builder = new MapStatus.Builder(); | |
| 117 | + Point screenPoint = ScreenUtil.getScreenPoint(context); | |
| 118 | + if (null != screenPoint) { | |
| 119 | + builder.targetScreen(new Point(screenPoint.x / 2, screenPoint.y / 3)); | |
| 120 | + } | |
| 121 | + getView().baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); | |
| 122 | + } | |
| 101 | 123 | } |
| 102 | 124 | } |
| 103 | 125 | }); | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/presenter/LineUpAgainPresenter.java
| ... | ... | @@ -82,10 +82,10 @@ public class LineUpAgainPresenter extends MvpBasePresenter<LineUpAgainView> { |
| 82 | 82 | //判断是否完成 |
| 83 | 83 | boolean isFinish = MyMapUtil.checkIsFinishTrace(importPoints, resultPoints, Constant.PASS_RATE); |
| 84 | 84 | if (isFinish) { |
| 85 | - Toast.makeText(context, "完成", Toast.LENGTH_LONG).show(); | |
| 85 | +// Toast.makeText(context, "完成", Toast.LENGTH_LONG).show(); | |
| 86 | 86 | failedEntity.setIsFinish("1"); |
| 87 | 87 | } else { |
| 88 | - Toast.makeText(context, "没有完成", Toast.LENGTH_LONG).show(); | |
| 88 | +// Toast.makeText(context, "没有完成", Toast.LENGTH_LONG).show(); | |
| 89 | 89 | failedEntity.setIsFinish("0"); |
| 90 | 90 | } |
| 91 | 91 | saveRouteData(context, failedEntity, onResultListener); | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/presenter/RunningFinishFragmetPresenter.java
| ... | ... | @@ -2,10 +2,13 @@ package com.cnlive.moudle.pedometer.frame.presenter; |
| 2 | 2 | |
| 3 | 3 | import android.app.Activity; |
| 4 | 4 | import android.content.Context; |
| 5 | +import android.graphics.Point; | |
| 5 | 6 | import android.text.TextUtils; |
| 6 | 7 | import android.util.Log; |
| 7 | 8 | import android.widget.Toast; |
| 8 | 9 | |
| 10 | +import com.baidu.mapapi.map.MapStatus; | |
| 11 | +import com.baidu.mapapi.map.MapStatusUpdateFactory; | |
| 9 | 12 | import com.baidu.mapapi.model.LatLng; |
| 10 | 13 | import com.baidu.mapapi.utils.DistanceUtil; |
| 11 | 14 | import com.baidu.trace.LBSTraceClient; |
| ... | ... | @@ -29,6 +32,7 @@ import com.cnlive.moudle.pedometer.ui.widget.SelectDialog; |
| 29 | 32 | import com.cnlive.moudle.pedometer.utils.GsonUtil; |
| 30 | 33 | import com.cnlive.moudle.pedometer.utils.MyMapUtil; |
| 31 | 34 | import com.cnlive.moudle.pedometer.utils.QMUITipDialogUtil; |
| 35 | +import com.cnlive.moudle.pedometer.utils.ScreenUtil; | |
| 32 | 36 | import com.cnlive.moudle.pedometer.utils.StepUtil; |
| 33 | 37 | import com.example.moudle_pedometer.R; |
| 34 | 38 | import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter; |
| ... | ... | @@ -58,10 +62,10 @@ public class RunningFinishFragmetPresenter extends MvpBasePresenter<RunningFinis |
| 58 | 62 | String employTime = runningFinishBean.getEmployTime(); |
| 59 | 63 | //路线全程里数 |
| 60 | 64 | String mileage = ""; |
| 61 | - if ("--".equals(runningFinishBean.getRunDistance())) { | |
| 65 | + if (null == userStepEntity.getStepCount() || TextUtils.isEmpty(userStepEntity.getStepCount())) { | |
| 62 | 66 | mileage = "0"; |
| 63 | 67 | } else { |
| 64 | - mileage = runningFinishBean.getRunDistance(); | |
| 68 | + mileage = StepUtil.getWalkDistanceKM(Long.parseLong(userStepEntity.getStepCount())) + ""; | |
| 65 | 69 | } |
| 66 | 70 | //配速 |
| 67 | 71 | String pace = ""; |
| ... | ... | @@ -218,7 +222,14 @@ public class RunningFinishFragmetPresenter extends MvpBasePresenter<RunningFinis |
| 218 | 222 | if (userStepEntity.getPauseCount() == 0) { |
| 219 | 223 | MyMapUtil.drawHistoryTrack(context, getView().baiduMap, resultPoints, SortType.asc, R.color.red, R.drawable.icon_start, R.drawable.icon_end); |
| 220 | 224 | MyMapUtil.setMapAutoZoom(getView().baiduMap, resultPoints, -1.5f); |
| 221 | - | |
| 225 | + if (null != getView()) { | |
| 226 | + MapStatus.Builder builder = new MapStatus.Builder(); | |
| 227 | + Point screenPoint = ScreenUtil.getScreenPoint(context); | |
| 228 | + if (null != screenPoint) { | |
| 229 | + builder.targetScreen(new Point(screenPoint.x / 2, screenPoint.y / 3)); | |
| 230 | + } | |
| 231 | + getView().baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); | |
| 232 | + } | |
| 222 | 233 | //没有点击暂停 |
| 223 | 234 | //先判断是否到达终点 |
| 224 | 235 | checkUserIsFinish(resultPoints, userStepEntity, runningFinishBean, context); |
| ... | ... | @@ -241,8 +252,16 @@ public class RunningFinishFragmetPresenter extends MvpBasePresenter<RunningFinis |
| 241 | 252 | if (importPoints != null) { |
| 242 | 253 | MyMapUtil.drawHistoryTrack(context, getView().baiduMap, resultPoints, SortType.asc, R.color.red, 0, R.drawable.icon_end); |
| 243 | 254 | MyMapUtil.setMapAutoZoom(getView().baiduMap, allResults, -2f); |
| 255 | + if (null != getView()) { | |
| 256 | + MapStatus.Builder builder = new MapStatus.Builder(); | |
| 257 | + Point screenPoint = ScreenUtil.getScreenPoint(context); | |
| 258 | + if (null != screenPoint) { | |
| 259 | + builder.targetScreen(new Point(screenPoint.x / 2, screenPoint.y / 3)); | |
| 260 | + } | |
| 261 | + getView().baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); | |
| 262 | + } | |
| 244 | 263 | //先判断是否到达终点 |
| 245 | - checkUserIsFinish(resultPoints, userStepEntity, runningFinishBean, context); | |
| 264 | + checkUserIsFinish(allResults, userStepEntity, runningFinishBean, context); | |
| 246 | 265 | saveRouteData(context, userStepEntity, runningFinishBean); |
| 247 | 266 | } |
| 248 | 267 | |
| ... | ... | @@ -315,10 +334,10 @@ public class RunningFinishFragmetPresenter extends MvpBasePresenter<RunningFinis |
| 315 | 334 | //判断是否完成 |
| 316 | 335 | boolean isFinish = MyMapUtil.checkIsFinishTrace(importPoints, resultPoints, Constant.PASS_RATE); |
| 317 | 336 | if (isFinish) { |
| 318 | - Toast.makeText(context, "完成", Toast.LENGTH_LONG).show(); | |
| 337 | +// Toast.makeText(context, "完成", Toast.LENGTH_LONG).show(); | |
| 319 | 338 | runningFinishBean.setIsFinish("1"); |
| 320 | 339 | } else { |
| 321 | - Toast.makeText(context, "没有完成", Toast.LENGTH_LONG).show(); | |
| 340 | +// Toast.makeText(context, "没有完成", Toast.LENGTH_LONG).show(); | |
| 322 | 341 | runningFinishBean.setIsFinish("0"); |
| 323 | 342 | } |
| 324 | 343 | } |
| ... | ... | @@ -352,7 +371,7 @@ public class RunningFinishFragmetPresenter extends MvpBasePresenter<RunningFinis |
| 352 | 371 | StepUtil.clearRunData(context, CommonInfo.getUserId(context)); |
| 353 | 372 | CommonInfo.reset(context); |
| 354 | 373 | //用户跑完了,更新一下按钮 |
| 355 | - EventBus.getDefault().post(new MessageEvent(Constant.UPDATE_RACE_STATE_BTN,"")); | |
| 374 | + EventBus.getDefault().post(new MessageEvent(Constant.UPDATE_RACE_STATE_BTN, "")); | |
| 356 | 375 | //跳转到上传失败列表 |
| 357 | 376 | LineUpAgainActivity.newInstance(context); |
| 358 | 377 | //关闭当前窗口 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/presenter/UploadFailDetailFragmentPresenter.java
| ... | ... | @@ -115,13 +115,13 @@ public class UploadFailDetailFragmentPresenter extends MvpBasePresenter<UploadFa |
| 115 | 115 | //判断是否完成 |
| 116 | 116 | boolean isFinish = MyMapUtil.checkIsFinishTrace(importPoints, resultPoints, Constant.PASS_RATE); |
| 117 | 117 | if (isFinish) { |
| 118 | - Toast.makeText(context, "完成", Toast.LENGTH_LONG).show(); | |
| 118 | +// Toast.makeText(context, "完成", Toast.LENGTH_LONG).show(); | |
| 119 | 119 | failedEntity.setIsFinish("1"); |
| 120 | 120 | if (getView() != null) { |
| 121 | 121 | getView().updateIsFinish("1"); |
| 122 | 122 | } |
| 123 | 123 | } else { |
| 124 | - Toast.makeText(context, "没有完成", Toast.LENGTH_LONG).show(); | |
| 124 | +// Toast.makeText(context, "没有完成", Toast.LENGTH_LONG).show(); | |
| 125 | 125 | failedEntity.setIsFinish("0"); |
| 126 | 126 | if (getView() != null) { |
| 127 | 127 | getView().updateIsFinish("0"); |
| ... | ... | @@ -158,13 +158,13 @@ public class UploadFailDetailFragmentPresenter extends MvpBasePresenter<UploadFa |
| 158 | 158 | //判断是否完成 |
| 159 | 159 | boolean isFinish = MyMapUtil.checkIsFinishTrace(importPoints, allResultPoints, Constant.PASS_RATE); |
| 160 | 160 | if (isFinish) { |
| 161 | - Toast.makeText(context, "完成", Toast.LENGTH_LONG).show(); | |
| 161 | +// Toast.makeText(context, "完成", Toast.LENGTH_LONG).show(); | |
| 162 | 162 | failedEntity.setIsFinish("1"); |
| 163 | 163 | if (getView() != null) { |
| 164 | 164 | getView().updateIsFinish("1"); |
| 165 | 165 | } |
| 166 | 166 | } else { |
| 167 | - Toast.makeText(context, "没有完成", Toast.LENGTH_LONG).show(); | |
| 167 | +// Toast.makeText(context, "没有完成", Toast.LENGTH_LONG).show(); | |
| 168 | 168 | failedEntity.setIsFinish("0"); |
| 169 | 169 | if (getView() != null) { |
| 170 | 170 | getView().updateIsFinish("0"); | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunMainFragmentView.java
| ... | ... | @@ -74,7 +74,7 @@ public class RunMainFragmentView implements MvpView { |
| 74 | 74 | public MyLocationListenner myListener = new MyLocationListenner(); |
| 75 | 75 | private String employTime = ""; |
| 76 | 76 | private LatLng endLatLng;//终点坐标 |
| 77 | - private TipDialog tipDialog; | |
| 77 | + private TipDialog endTipDialog; | |
| 78 | 78 | //创建震动服务对象 |
| 79 | 79 | private Vibrator mVibrator; |
| 80 | 80 | private boolean isfirstEndTip = true; |
| ... | ... | @@ -131,6 +131,10 @@ public class RunMainFragmentView implements MvpView { |
| 131 | 131 | * 初始化相关视图 |
| 132 | 132 | */ |
| 133 | 133 | public void initView(RunRaceDetailInfo runRaceDetailInfo) { |
| 134 | + if (getContext() == null) { | |
| 135 | + return; | |
| 136 | + } | |
| 137 | + initEndTipDialog(); | |
| 134 | 138 | //获取手机震动服务 |
| 135 | 139 | mVibrator = (Vibrator) getContext().getSystemService(Service.VIBRATOR_SERVICE); |
| 136 | 140 | uid = CommonInfo.getUserId(getContext()); |
| ... | ... | @@ -342,6 +346,9 @@ public class RunMainFragmentView implements MvpView { |
| 342 | 346 | //继续记录轨迹 |
| 343 | 347 | if (StepService.mClient != null && StepService.traceListener != null) { |
| 344 | 348 | CommonInfo.setTsRunBaiduTraceService(getContext(), true); |
| 349 | + CommonInfo.setIsRunKeepAliveService(getContext(), true); | |
| 350 | + CommonInfo.setIsRunStepService(getContext(), true); | |
| 351 | + CommonInfo.setIsWriteUserStep(getContext(), true); | |
| 345 | 352 | StepService.mClient.startTrace(StepService.mTrace, StepService.traceListener); |
| 346 | 353 | } |
| 347 | 354 | needWriteDataFlag = true; |
| ... | ... | @@ -405,8 +412,8 @@ public class RunMainFragmentView implements MvpView { |
| 405 | 412 | public void onClick(SelectDialog dialog) { |
| 406 | 413 | //停止计时 |
| 407 | 414 | fragment.binding.chronometer.stop(); |
| 408 | - //设置状态标志位 | |
| 409 | - setStopStartFlag(); | |
| 415 | + //停止服务 | |
| 416 | + stopRunService(); | |
| 410 | 417 | //设置运动结束时间戳 |
| 411 | 418 | StepUtil.setUserFinishTimeStamp(getContext(), uid); |
| 412 | 419 | fragment.binding.cpCurrent.setVisibility(View.GONE); |
| ... | ... | @@ -576,6 +583,17 @@ public class RunMainFragmentView implements MvpView { |
| 576 | 583 | }); |
| 577 | 584 | } |
| 578 | 585 | |
| 586 | + private void initEndTipDialog() { | |
| 587 | + endTipDialog = new TipDialog(getContext(), getContext().getResources().getString(R.string.run_race_arrive_end_tip), "好的", R.color.green_round, new TipDialog.DialogInterface() { | |
| 588 | + @Override | |
| 589 | + public void onClick(TipDialog dialog) { | |
| 590 | + dialog.dismiss(); | |
| 591 | + } | |
| 592 | + }); | |
| 593 | + endTipDialog.setCancelable(false); | |
| 594 | + endTipDialog.setCanceledOnTouchOutside(false); | |
| 595 | + } | |
| 596 | + | |
| 579 | 597 | /** |
| 580 | 598 | * 暂停按钮 |
| 581 | 599 | */ |
| ... | ... | @@ -641,18 +659,18 @@ public class RunMainFragmentView implements MvpView { |
| 641 | 659 | Log.e(TAG, "setSQLPauseTime: "); |
| 642 | 660 | // if (needWriteDataFlag) { |
| 643 | 661 | //将当前计时器时间戳写入数据库 |
| 644 | - UserStepEntity userStepEntity = StepUtil.getUserStepData(fragment.getActivity(), id); | |
| 645 | - if (userStepEntity != null) { | |
| 646 | - userStepEntity.setChronometerBase(fragment.binding.chronometer.getBase()); | |
| 647 | - //设置当前暂停的时间戳 | |
| 648 | - userStepEntity.setRecordTime(SystemClock.elapsedRealtime()); | |
| 649 | - //设置当前用户暂停的时间戳 | |
| 650 | - userStepEntity.setUserPauseTimeStamp(TimeUtil.getNowTimeStamp()); | |
| 651 | - //设置暂停次数 | |
| 652 | - userStepEntity.setPauseCount(userStepEntity.getPauseCount() + 1); | |
| 653 | - //更新数据 | |
| 654 | - StepUtil.updateStepData(fragment.getActivity(), userStepEntity); | |
| 655 | - } | |
| 662 | + UserStepEntity userStepEntity = StepUtil.getUserStepData(fragment.getActivity(), id); | |
| 663 | + if (userStepEntity != null) { | |
| 664 | + userStepEntity.setChronometerBase(fragment.binding.chronometer.getBase()); | |
| 665 | + //设置当前暂停的时间戳 | |
| 666 | + userStepEntity.setRecordTime(SystemClock.elapsedRealtime()); | |
| 667 | + //设置当前用户暂停的时间戳 | |
| 668 | + userStepEntity.setUserPauseTimeStamp(TimeUtil.getNowTimeStamp()); | |
| 669 | + //设置暂停次数 | |
| 670 | + userStepEntity.setPauseCount(userStepEntity.getPauseCount() + 1); | |
| 671 | + //更新数据 | |
| 672 | + StepUtil.updateStepData(fragment.getActivity(), userStepEntity); | |
| 673 | + } | |
| 656 | 674 | // } |
| 657 | 675 | } |
| 658 | 676 | |
| ... | ... | @@ -785,7 +803,7 @@ public class RunMainFragmentView implements MvpView { |
| 785 | 803 | LatLng current = new LatLng(location.getLatitude(), location.getLongitude()); |
| 786 | 804 | if (null != current) { |
| 787 | 805 | //开始比较数据 |
| 788 | - double distance = DistanceUtil.getDistance(current, endLatLng); | |
| 806 | + int distance = (int) DistanceUtil.getDistance(current, endLatLng); | |
| 789 | 807 | if (distance < Constant.LOCA_END_POINT_ACCURACY) { |
| 790 | 808 | //设置数据 |
| 791 | 809 | if (userStepEntity != null) { |
| ... | ... | @@ -800,25 +818,7 @@ public class RunMainFragmentView implements MvpView { |
| 800 | 818 | isfirstEndTip = false; |
| 801 | 819 | } |
| 802 | 820 | //进行提示 |
| 803 | - if (null == tipDialog) { | |
| 804 | - ChineseToSpeechUtil.speech(getContext(), "您已到达终点附近,可以结束运动了!"); | |
| 805 | - if (mVibrator != null) { | |
| 806 | - //设置震动周期,数组表示时间:等待+执行,单位是毫秒,下面操作代表:等待100,执行100,等待100,执行1000, | |
| 807 | - //后面的数字如果为-1代表不重复,之执行一次,其他代表会重复,0代表从数组的第0个位置开始 | |
| 808 | - mVibrator.vibrate(new long[]{Constant.VIBRATOR_DELAY_TIME, Constant.VIBRATOR_RUN_TIME, Constant.VIBRATOR_DELAY_TIME, Constant.VIBRATOR_RUN_TIME}, Constant.VIBRATOR_REPEAT_TIME); | |
| 809 | - } | |
| 810 | - tipDialog = new TipDialog(getContext(), getContext().getResources().getString(R.string.run_race_arrive_end_tip), "好的", R.color.green_round, new TipDialog.DialogInterface() { | |
| 811 | - @Override | |
| 812 | - public void onClick(TipDialog dialog) { | |
| 813 | - dialog.dismiss(); | |
| 814 | - } | |
| 815 | - }); | |
| 816 | - tipDialog.setCancelable(false); | |
| 817 | - tipDialog.setCanceledOnTouchOutside(false); | |
| 818 | - } | |
| 819 | - if (!tipDialog.isShowing()) { | |
| 820 | - tipDialog.show(); | |
| 821 | - } | |
| 821 | + showEndTipDialog(); | |
| 822 | 822 | } |
| 823 | 823 | } |
| 824 | 824 | } |
| ... | ... | @@ -826,23 +826,57 @@ public class RunMainFragmentView implements MvpView { |
| 826 | 826 | |
| 827 | 827 | } |
| 828 | 828 | |
| 829 | + public void showEndTipDialog() { | |
| 830 | + if (null == getContext()) { | |
| 831 | + return; | |
| 832 | + } | |
| 833 | + //进行提示 | |
| 834 | + if (null != endTipDialog && !endTipDialog.isShowing()) { | |
| 835 | + endTipDialog.show(); | |
| 836 | + ChineseToSpeechUtil.speech(getContext(), "您已到达终点附近,可以结束运动了!"); | |
| 837 | + if (mVibrator != null) { | |
| 838 | + //设置震动周期,数组表示时间:等待+执行,单位是毫秒,下面操作代表:等待100,执行100,等待100,执行1000, | |
| 839 | + //后面的数字如果为-1代表不重复,之执行一次,其他代表会重复,0代表从数组的第0个位置开始 | |
| 840 | + mVibrator.vibrate(new long[]{Constant.VIBRATOR_DELAY_TIME, Constant.VIBRATOR_RUN_TIME, Constant.VIBRATOR_DELAY_TIME, Constant.VIBRATOR_RUN_TIME}, Constant.VIBRATOR_REPEAT_TIME); | |
| 841 | + } | |
| 842 | + } | |
| 843 | + } | |
| 844 | + | |
| 829 | 845 | /** |
| 830 | 846 | * 设置停止状态标志位 |
| 831 | 847 | */ |
| 832 | 848 | private void setStopStartFlag() { |
| 833 | 849 | CommonInfo.setTsRunBaiduTraceService(getContext(), false); |
| 834 | 850 | CommonInfo.setIsRunKeepAliveService(getContext(), false); |
| 851 | + CommonInfo.setIsRunStepService(getContext(), false); | |
| 835 | 852 | CommonInfo.setIsWriteUserStep(getContext(), false); |
| 836 | 853 | if (StepService.mClient != null) { |
| 837 | 854 | StepService.mClient.stopGather(StepService.traceListener); |
| 838 | 855 | // StepService.CURRENT_STEP = 0; |
| 839 | 856 | } |
| 857 | +// fragment.getActivity().stopService(new Intent(fragment.getActivity(), StepService.class)); | |
| 858 | + } | |
| 859 | + | |
| 860 | + /** | |
| 861 | + * 停止计步服务 | |
| 862 | + */ | |
| 863 | + private void stopRunService() { | |
| 864 | + CommonInfo.setTsRunBaiduTraceService(getContext(), false); | |
| 865 | + CommonInfo.setIsRunKeepAliveService(getContext(), false); | |
| 866 | + CommonInfo.setIsRunStepService(getContext(), false); | |
| 867 | + CommonInfo.setIsWriteUserStep(getContext(), false); | |
| 868 | + if (StepService.mClient != null) { | |
| 869 | + StepService.mClient.stopGather(StepService.traceListener); | |
| 870 | + } | |
| 840 | 871 | fragment.getActivity().stopService(new Intent(fragment.getActivity(), StepService.class)); |
| 872 | + fragment.getActivity().stopService(new Intent(fragment.getActivity(), KeepLiveService.class)); | |
| 873 | + | |
| 841 | 874 | } |
| 842 | 875 | |
| 843 | 876 | public void onDestroy() { |
| 844 | 877 | if (mLocClient != null) { |
| 845 | 878 | mLocClient.stop(); |
| 879 | + mLocClient = null; | |
| 846 | 880 | } |
| 847 | 881 | } |
| 848 | 882 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunRaceDetailFragmentView.java
| ... | ... | @@ -591,8 +591,9 @@ public class RunRaceDetailFragmentView implements MvpView, SensorEventListener { |
| 591 | 591 | CommonInfo.resetRace(getContext()); |
| 592 | 592 | dialog.dismiss(); |
| 593 | 593 | //重置按钮 |
| 594 | - fragment.binding.tvRunNow.setText("立即开始"); | |
| 595 | - fragment.binding.rlScrollViewStartBtn.setTag(BTN_START_RACE); | |
| 594 | + if (null != runRaceDetailInfo) { | |
| 595 | + initStartBtnState(runRaceDetailInfo); | |
| 596 | + } | |
| 596 | 597 | } |
| 597 | 598 | }, "是", new SelectDialog.DialogInterface() { |
| 598 | 599 | @Override |
| ... | ... | @@ -620,8 +621,9 @@ public class RunRaceDetailFragmentView implements MvpView, SensorEventListener { |
| 620 | 621 | //清除数据 |
| 621 | 622 | CommonInfo.resetRace(getContext()); |
| 622 | 623 | //更改当前按钮 |
| 623 | - fragment.binding.tvRunNow.setText("立即开始"); | |
| 624 | - fragment.binding.rlScrollViewStartBtn.setTag(BTN_START_RACE); | |
| 624 | + if (null != runRaceDetailInfo) { | |
| 625 | + initStartBtnState(runRaceDetailInfo); | |
| 626 | + } | |
| 625 | 627 | |
| 626 | 628 | } |
| 627 | 629 | }, "是", new SelectDialog.DialogInterface() { |
| ... | ... | @@ -743,11 +745,13 @@ public class RunRaceDetailFragmentView implements MvpView, SensorEventListener { |
| 743 | 745 | private void stopStepService() { |
| 744 | 746 | CommonInfo.setTsRunBaiduTraceService(getContext(), false); |
| 745 | 747 | CommonInfo.setIsRunKeepAliveService(getContext(), false); |
| 748 | + CommonInfo.setIsRunStepService(getContext(), false); | |
| 746 | 749 | CommonInfo.setIsWriteUserStep(getContext(), false); |
| 747 | 750 | CommonInfo.setIsFirstStepSendTraceTip(getContext(), true); |
| 748 | 751 | if (StepService.mClient != null) { |
| 749 | 752 | StepService.mClient.stopGather(StepService.traceListener); |
| 750 | 753 | } |
| 754 | + fragment.getActivity().stopService(new Intent(fragment.getActivity(), KeepLiveService.class)); | |
| 751 | 755 | fragment.getActivity().stopService(new Intent(fragment.getActivity(), StepService.class)); |
| 752 | 756 | } |
| 753 | 757 | |
| ... | ... | @@ -808,7 +812,7 @@ public class RunRaceDetailFragmentView implements MvpView, SensorEventListener { |
| 808 | 812 | //可选,设置是否需要设备方向结果 |
| 809 | 813 | option.setNeedDeviceDirect(false); |
| 810 | 814 | //设置打开自动回调位置模式,该开关打开后,期间只要定位SDK检测到位置变化就会主动回调给开发者 |
| 811 | - option.setOpenAutoNotifyMode(3000, 1, LocationClientOption.LOC_SENSITIVITY_HIGHT); | |
| 815 | +// option.setOpenAutoNotifyMode(3000, 1, LocationClientOption.LOC_SENSITIVITY_HIGHT); | |
| 812 | 816 | mLocClient.setLocOption(option); |
| 813 | 817 | mLocClient.start(); |
| 814 | 818 | //设置地图加载完毕监听 |
| ... | ... | @@ -1100,9 +1104,12 @@ public class RunRaceDetailFragmentView implements MvpView, SensorEventListener { |
| 1100 | 1104 | if ((currnetTime - userPauseTime) <= (9 * 60 * 60 * 1000)) { |
| 1101 | 1105 | Log.e(TAG, "小于9小时"); |
| 1102 | 1106 | fragment.binding.tvRunNow.setText("继续运动"); |
| 1107 | + fragment.binding.rlScrollViewStartBtn.setBackgroundColor(getContext().getResources().getColor(R.color.green_round)); | |
| 1103 | 1108 | fragment.binding.rlScrollViewStartBtn.setTag(BTN_CONTINUE_RACE); |
| 1104 | 1109 | } else { |
| 1105 | 1110 | Log.e(TAG, "大于9小时"); |
| 1111 | + //停止服务 | |
| 1112 | + stopStepService(); | |
| 1106 | 1113 | //重置数据 |
| 1107 | 1114 | CommonInfo.resetRace(getContext()); |
| 1108 | 1115 | //清空数据库 |
| ... | ... | @@ -1203,7 +1210,7 @@ public class RunRaceDetailFragmentView implements MvpView, SensorEventListener { |
| 1203 | 1210 | if (isFirstLoc) { |
| 1204 | 1211 | isFirstLoc = false; |
| 1205 | 1212 | if (location.getRadius() > Constant.LOCA_ACCURACY) { |
| 1206 | - Toast.makeText(getContext(), "当前定位误差为:" + location.getRadius() + "米,请您移动至空旷地带!", Toast.LENGTH_SHORT).show(); | |
| 1213 | + Toast.makeText(getContext(), "当前定位误差为:" + (int) location.getRadius() + "米,请您移动至空旷地带!", Toast.LENGTH_SHORT).show(); | |
| 1207 | 1214 | } |
| 1208 | 1215 | |
| 1209 | 1216 | } else { | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunningMapFragmentView.java
| ... | ... | @@ -89,7 +89,7 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 89 | 89 | private List<LatLng> currentPoints; |
| 90 | 90 | private LatLng endLatLng;//终点坐标 |
| 91 | 91 | private UserStepEntity userStepEntity; |
| 92 | - private TipDialog tipDialog; | |
| 92 | + private TipDialog endTipDialog; | |
| 93 | 93 | //创建震动服务对象 |
| 94 | 94 | private Vibrator mVibrator; |
| 95 | 95 | private boolean isfirstEndTip = true;//是否是第一次提示到达终点 |
| ... | ... | @@ -106,6 +106,7 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 106 | 106 | if (getContext() == null) { |
| 107 | 107 | return; |
| 108 | 108 | } |
| 109 | + initEndTipDialog(); | |
| 109 | 110 | //获取手机震动服务 |
| 110 | 111 | mVibrator = (Vibrator) getContext().getSystemService(Service.VIBRATOR_SERVICE); |
| 111 | 112 | userStepEntity = StepUtil.getUserStepData(getContext(), CommonInfo.getUserId(getContext())); |
| ... | ... | @@ -213,7 +214,7 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 213 | 214 | //minTimeInterval - 最短定位时间间隔,单位毫秒,最小值0,开发者可以在设置希望的位置回调最短时间间隔 |
| 214 | 215 | //minDistance - 最短定位距离间隔,单位米,最小值0,开发者可以设置希望的位置回调距离间隔 |
| 215 | 216 | //locSensitivity - 定位变化敏感程度,LOC_SENSITIVITY_HIGHT,LOC_SENSITIVITY_MIDDLE,LOC_SENSITIVITY_LOW |
| 216 | - option.setOpenAutoNotifyMode(3000, 1, LocationClientOption.LOC_SENSITIVITY_HIGHT); | |
| 217 | +// option.setOpenAutoNotifyMode(3000, 1, LocationClientOption.LOC_SENSITIVITY_HIGHT); | |
| 217 | 218 | //可选,定位SDK内部是一个service,并放到了独立进程。 |
| 218 | 219 | //设置是否在stop的时候杀死这个进程,默认(建议)不杀死,即setIgnoreKillProcess(true) |
| 219 | 220 | option.setIgnoreKillProcess(true); |
| ... | ... | @@ -318,7 +319,7 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 318 | 319 | if (isFirstLoc) { |
| 319 | 320 | isFirstLoc = false; |
| 320 | 321 | if (location.getRadius() > Constant.LOCA_ACCURACY) { |
| 321 | - Toast.makeText(getContext(), "当前定位误差为:" + location.getRadius() + "米,请您移动至空旷地带!", Toast.LENGTH_SHORT).show(); | |
| 322 | + Toast.makeText(getContext(), "当前定位误差为:" + (int)location.getRadius() + "米,请您移动至空旷地带!", Toast.LENGTH_SHORT).show(); | |
| 322 | 323 | } |
| 323 | 324 | |
| 324 | 325 | |
| ... | ... | @@ -345,7 +346,7 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 345 | 346 | LatLng current = new LatLng(location.getLatitude(), location.getLongitude()); |
| 346 | 347 | if (null != current) { |
| 347 | 348 | //开始比较数据 |
| 348 | - double distance = DistanceUtil.getDistance(current, endLatLng); | |
| 349 | + int distance = (int) DistanceUtil.getDistance(current, endLatLng); | |
| 349 | 350 | if (distance < Constant.LOCA_END_POINT_ACCURACY) { |
| 350 | 351 | //设置数据 |
| 351 | 352 | if (userStepEntity != null) { |
| ... | ... | @@ -361,26 +362,7 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 361 | 362 | isfirstEndTip = false; |
| 362 | 363 | } |
| 363 | 364 | //进行提示 |
| 364 | - if (null == tipDialog) { | |
| 365 | - ChineseToSpeechUtil.speech(getContext(), "您已到达终点附近,可以结束运动了!"); | |
| 366 | - if (mVibrator != null) { | |
| 367 | - //设置震动周期,数组表示时间:等待+执行,单位是毫秒,下面操作代表:等待100,执行100,等待100,执行1000, | |
| 368 | - //后面的数字如果为-1代表不重复,之执行一次,其他代表会重复,0代表从数组的第0个位置开始 | |
| 369 | - mVibrator.vibrate(new long[]{Constant.VIBRATOR_DELAY_TIME, Constant.VIBRATOR_RUN_TIME, Constant.VIBRATOR_DELAY_TIME, Constant.VIBRATOR_RUN_TIME}, Constant.VIBRATOR_REPEAT_TIME); | |
| 370 | - } | |
| 371 | - | |
| 372 | - tipDialog = new TipDialog(getContext(), getContext().getResources().getString(R.string.run_race_arrive_end_tip), "好的", R.color.green_round, new TipDialog.DialogInterface() { | |
| 373 | - @Override | |
| 374 | - public void onClick(TipDialog dialog) { | |
| 375 | - dialog.dismiss(); | |
| 376 | - } | |
| 377 | - }); | |
| 378 | - tipDialog.setCancelable(false); | |
| 379 | - tipDialog.setCanceledOnTouchOutside(false); | |
| 380 | - } | |
| 381 | - if (!tipDialog.isShowing()) { | |
| 382 | - tipDialog.show(); | |
| 383 | - } | |
| 365 | + showEndTipDialog(); | |
| 384 | 366 | } |
| 385 | 367 | } |
| 386 | 368 | } |
| ... | ... | @@ -430,6 +412,32 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 430 | 412 | } |
| 431 | 413 | } |
| 432 | 414 | |
| 415 | + private void initEndTipDialog() { | |
| 416 | + endTipDialog = new TipDialog(getContext(), getContext().getResources().getString(R.string.run_race_arrive_end_tip), "好的", R.color.green_round, new TipDialog.DialogInterface() { | |
| 417 | + @Override | |
| 418 | + public void onClick(TipDialog dialog) { | |
| 419 | + dialog.dismiss(); | |
| 420 | + } | |
| 421 | + }); | |
| 422 | + endTipDialog.setCancelable(false); | |
| 423 | + endTipDialog.setCanceledOnTouchOutside(false); | |
| 424 | + } | |
| 425 | + | |
| 426 | + public void showEndTipDialog() { | |
| 427 | + if (null == getContext()) { | |
| 428 | + return; | |
| 429 | + } | |
| 430 | + //进行提示 | |
| 431 | + if (null != endTipDialog && !endTipDialog.isShowing()) { | |
| 432 | + endTipDialog.show(); | |
| 433 | + ChineseToSpeechUtil.speech(getContext(), "您已到达终点附近,可以结束运动了!"); | |
| 434 | + if (mVibrator != null) { | |
| 435 | + //设置震动周期,数组表示时间:等待+执行,单位是毫秒,下面操作代表:等待100,执行100,等待100,执行1000, | |
| 436 | + //后面的数字如果为-1代表不重复,之执行一次,其他代表会重复,0代表从数组的第0个位置开始 | |
| 437 | + mVibrator.vibrate(new long[]{Constant.VIBRATOR_DELAY_TIME, Constant.VIBRATOR_RUN_TIME, Constant.VIBRATOR_DELAY_TIME, Constant.VIBRATOR_RUN_TIME}, Constant.VIBRATOR_REPEAT_TIME); | |
| 438 | + } | |
| 439 | + } | |
| 440 | + } | |
| 433 | 441 | |
| 434 | 442 | /** |
| 435 | 443 | * 同步计时器 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/model/Constant.java
| ... | ... | @@ -24,6 +24,7 @@ public class Constant { |
| 24 | 24 | public static final int COLL_SERVICE_STEP_COUNT_ONRESUME = 15;//运营从后台回到前台,更新步数 |
| 25 | 25 | public static final int UPDATA_COLL_TRACE_LIST = 16;//更新轨迹列表 |
| 26 | 26 | public static final int UPDATE_RACE_STATE_BTN = 17;//更新赛事详情页按钮数据 |
| 27 | + public static final int ARRIVE_END_POINT = 18;//到达终点附近 | |
| 27 | 28 | /*************************************用户其他值,非标志位************************************************************/ |
| 28 | 29 | public static long SERVICE_ID = 0;//公司账号 |
| 29 | 30 | // public static final long SERVICE_ID = 213553; |
| ... | ... | @@ -31,7 +32,7 @@ public class Constant { |
| 31 | 32 | public static final int GATHER_INTERVAL = 2;//位置采集周期 |
| 32 | 33 | public static final int PACK_INTERVAL = 10;//位置采集周期 |
| 33 | 34 | public static final int VIBRATOR_DELAY_TIME = 100;//震动等待时间(ms) |
| 34 | - public static final int VIBRATOR_RUN_TIME = 1000;//震动执行时间(ms) | |
| 35 | + public static final int VIBRATOR_RUN_TIME = 2000;//震动执行时间(ms) | |
| 35 | 36 | public static final int VIBRATOR_REPEAT_TIME = -1;//震动重复次数(-1代表不重复,之执行一次,其他代表会重复,0代表从数组的第0个位置开始) |
| 36 | 37 | /*****************************************运营工具其他值,非标志位****************************************************/ |
| 37 | 38 | public static final double PASS_RATE = 0.7;//通过率70% | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/receivers/ServiceReceiver.java
| ... | ... | @@ -23,6 +23,7 @@ public class ServiceReceiver extends BroadcastReceiver { |
| 23 | 23 | //唤醒锁 |
| 24 | 24 | private PowerManager.WakeLock wakeLock = null; |
| 25 | 25 | private final String TAG = "ServiceReceiver"; |
| 26 | + private AudioManager audioManager; | |
| 26 | 27 | |
| 27 | 28 | public ServiceReceiver() { |
| 28 | 29 | |
| ... | ... | @@ -105,7 +106,9 @@ public class ServiceReceiver extends BroadcastReceiver { |
| 105 | 106 | |
| 106 | 107 | private void initSound(Context context) { |
| 107 | 108 | try { |
| 108 | - AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); | |
| 109 | + if (null==audioManager){ | |
| 110 | + audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); | |
| 111 | + } | |
| 109 | 112 | int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); |
| 110 | 113 | if (0 == currentVolume) { |
| 111 | 114 | audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 1, AudioManager.FLAG_PLAY_SOUND); | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/service/KeepLiveService.java
| ... | ... | @@ -43,7 +43,7 @@ public class KeepLiveService extends Service implements MediaPlayer.OnCompletion |
| 43 | 43 | private NotificationManager mNM; |
| 44 | 44 | private Notification notification = null; |
| 45 | 45 | //是否在后台运行 |
| 46 | - public static boolean isKeepService = true; | |
| 46 | + public static boolean isKeepService = false; | |
| 47 | 47 | public static KeepLiveService instance; |
| 48 | 48 | private int startId; |
| 49 | 49 | private final String TAG = "KeepLiveService"; |
| ... | ... | @@ -52,6 +52,7 @@ public class KeepLiveService extends Service implements MediaPlayer.OnCompletion |
| 52 | 52 | private boolean isRegisterReceiver = false; |
| 53 | 53 | private boolean isStartForeground = false; |
| 54 | 54 | private final int NOTIFICATION_ID = 1; |
| 55 | + | |
| 55 | 56 | public KeepLiveService() { |
| 56 | 57 | } |
| 57 | 58 | |
| ... | ... | @@ -159,13 +160,25 @@ public class KeepLiveService extends Service implements MediaPlayer.OnCompletion |
| 159 | 160 | Log.e("isRun onStartCommand", "" + isRun); |
| 160 | 161 | |
| 161 | 162 | if (isRun) { |
| 162 | - if (runnable != null) { | |
| 163 | - handler.postDelayed(runnable, 5000); | |
| 164 | - } | |
| 163 | +// if (runnable != null) { | |
| 164 | +// handler.postDelayed(runnable, 5000); | |
| 165 | +// } | |
| 165 | 166 | showHideForegroundNotification(); |
| 166 | 167 | // startService(new Intent(getApplicationContext(), HideKeepTipService.class)); |
| 167 | 168 | // Log.e(TAG, "启动HideKeepTipService"); |
| 168 | 169 | startPlaySong(); |
| 170 | + } else { | |
| 171 | + try { | |
| 172 | + if (myReceiver != null && isRegisterReceiver) { | |
| 173 | + unregisterReceiver(myReceiver); | |
| 174 | + } | |
| 175 | + } catch (Exception e) { | |
| 176 | + Log.e(TAG, "run: "); | |
| 177 | + } | |
| 178 | + stopPlaySong(); | |
| 179 | + if (isStartForeground) { | |
| 180 | + stopForeground(true); | |
| 181 | + } | |
| 169 | 182 | } |
| 170 | 183 | return START_STICKY; |
| 171 | 184 | } |
| ... | ... | @@ -224,9 +237,9 @@ public class KeepLiveService extends Service implements MediaPlayer.OnCompletion |
| 224 | 237 | // .setContentText("正在计步,请勿关闭") |
| 225 | 238 | // .setSound(null) |
| 226 | 239 | // .build(); |
| 227 | - Intent notificationIntent = new Intent(this, PedometerMainActivity.class); | |
| 240 | +// Intent notificationIntent = new Intent(this, PedometerMainActivity.class); | |
| 228 | 241 | notification = new NotificationCompat.Builder(this, CHANNEL_ONE_ID) |
| 229 | - .setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0)) | |
| 242 | +// .setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0)) | |
| 230 | 243 | .setSmallIcon(R.mipmap.ic_launcher) |
| 231 | 244 | // .setCustomContentView(remoteViews) |
| 232 | 245 | .setContentTitle(getResources().getString(R.string.app_name)) |
| ... | ... | @@ -237,7 +250,7 @@ public class KeepLiveService extends Service implements MediaPlayer.OnCompletion |
| 237 | 250 | .build(); |
| 238 | 251 | // 0 隐藏前台服务通知 |
| 239 | 252 | startForeground(NOTIFICATION_ID, notification); |
| 240 | - isStartForeground=true; | |
| 253 | + isStartForeground = true; | |
| 241 | 254 | } |
| 242 | 255 | |
| 243 | 256 | @Override |
| ... | ... | @@ -295,11 +308,11 @@ public class KeepLiveService extends Service implements MediaPlayer.OnCompletion |
| 295 | 308 | if (isRun) { |
| 296 | 309 | Log.e(TAG, "重新播放"); |
| 297 | 310 | mediaPlayer.start(); |
| 298 | - Intent intent = new Intent("com.cnlive.strike.receiver.CollServiceReceiver"); | |
| 299 | - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
| 300 | - intent.setComponent(new ComponentName(getPackageName(), "com.cnlive.strike.receiver.CollServiceReceiver"));//高版本Android发送广播需要加这句 | |
| 301 | - } | |
| 302 | - sendBroadcast(intent); | |
| 311 | +// Intent intent = new Intent("com.cnlive.strike.receiver.CollServiceReceiver"); | |
| 312 | +// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
| 313 | +// intent.setComponent(new ComponentName(getPackageName(), "com.cnlive.strike.receiver.CollServiceReceiver"));//高版本Android发送广播需要加这句 | |
| 314 | +// } | |
| 315 | +// sendBroadcast(intent); | |
| 303 | 316 | } else { |
| 304 | 317 | Log.e(TAG, "停止重新播放"); |
| 305 | 318 | stopPlaySong(); | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/service/StepService.java
| ... | ... | @@ -26,6 +26,15 @@ import android.util.Log; |
| 26 | 26 | import android.widget.RemoteViews; |
| 27 | 27 | import android.widget.Toast; |
| 28 | 28 | |
| 29 | +import com.baidu.location.BDAbstractLocationListener; | |
| 30 | +import com.baidu.location.BDLocation; | |
| 31 | +import com.baidu.location.LocationClient; | |
| 32 | +import com.baidu.location.LocationClientOption; | |
| 33 | +import com.baidu.mapapi.map.MapStatus; | |
| 34 | +import com.baidu.mapapi.map.MapStatusUpdateFactory; | |
| 35 | +import com.baidu.mapapi.map.MyLocationData; | |
| 36 | +import com.baidu.mapapi.model.LatLng; | |
| 37 | +import com.baidu.mapapi.utils.DistanceUtil; | |
| 29 | 38 | import com.baidu.trace.LBSTraceClient; |
| 30 | 39 | import com.baidu.trace.Trace; |
| 31 | 40 | import com.baidu.trace.api.fence.AddMonitoredPersonResponse; |
| ... | ... | @@ -52,6 +61,7 @@ import com.baidu.trace.model.OnTraceListener; |
| 52 | 61 | import com.baidu.trace.model.PushMessage; |
| 53 | 62 | import com.baidu.trace.model.StatusCodes; |
| 54 | 63 | import com.cnlive.moudle.pedometer.commonInfo.CommonInfo; |
| 64 | +import com.cnlive.moudle.pedometer.frame.view.RunMainFragmentView; | |
| 55 | 65 | import com.cnlive.moudle.pedometer.model.Constant; |
| 56 | 66 | import com.cnlive.moudle.pedometer.model.MessageEvent; |
| 57 | 67 | import com.cnlive.moudle.pedometer.model.step.StepCount; |
| ... | ... | @@ -59,6 +69,7 @@ import com.cnlive.moudle.pedometer.model.step.StepValuePassListener; |
| 59 | 69 | import com.cnlive.moudle.pedometer.sql.db.DbCore; |
| 60 | 70 | import com.cnlive.moudle.pedometer.sql.entity.UserStepEntity; |
| 61 | 71 | import com.cnlive.moudle.pedometer.ui.activity.PedometerMainActivity; |
| 72 | +import com.cnlive.moudle.pedometer.utils.GsonUtil; | |
| 62 | 73 | import com.cnlive.moudle.pedometer.utils.ServiceUtils; |
| 63 | 74 | import com.cnlive.moudle.pedometer.utils.StepUtil; |
| 64 | 75 | import com.cnlive.moudle.pedometer.utils.TimeUtil; |
| ... | ... | @@ -141,7 +152,8 @@ public class StepService extends Service implements SensorEventListener { |
| 141 | 152 | private static boolean pauseFlag;//是否暂停 |
| 142 | 153 | private static int speedCurrentStep;//用于检测速度步数 |
| 143 | 154 | private boolean updateSpeedStepFlag;//是否是已经更新速度 |
| 144 | - | |
| 155 | + private LatLng endLatLng;//终点坐标 | |
| 156 | + private UserStepEntity userStepEntity; | |
| 145 | 157 | /****************************************************鹰眼轨迹相关************************************************/ |
| 146 | 158 | /** |
| 147 | 159 | * 轨迹服务监听器 |
| ... | ... | @@ -163,6 +175,10 @@ public class StepService extends Service implements SensorEventListener { |
| 163 | 175 | * 轨迹服务 |
| 164 | 176 | */ |
| 165 | 177 | public static Trace mTrace = null; |
| 178 | + //定位 | |
| 179 | + public MyLocationListenner myListener = new MyLocationListenner(); | |
| 180 | + private LocationClient mLocClient; | |
| 181 | + private boolean isHasSendEndTip = true;//是否发送到达终点提示 | |
| 166 | 182 | |
| 167 | 183 | public StepService() { |
| 168 | 184 | |
| ... | ... | @@ -506,7 +522,7 @@ public class StepService extends Service implements SensorEventListener { |
| 506 | 522 | Log.e(TAG, "onListMonitoredPersonCallback: "); |
| 507 | 523 | } |
| 508 | 524 | }; |
| 509 | - if (userStepEntity != null &&!TextUtils.isEmpty(userStepEntity.getFenceId())) { | |
| 525 | + if (userStepEntity != null && !TextUtils.isEmpty(userStepEntity.getFenceId())) { | |
| 510 | 526 | List<Long> fenids = new ArrayList<>(); |
| 511 | 527 | fenids.add(Long.parseLong(userStepEntity.getFenceId())); |
| 512 | 528 | MonitoredStatusRequest request1 = MonitoredStatusRequest.buildServerRequest(Constant.TAG, |
| ... | ... | @@ -553,6 +569,7 @@ public class StepService extends Service implements SensorEventListener { |
| 553 | 569 | } |
| 554 | 570 | }).start(); |
| 555 | 571 | startTimeCount(); |
| 572 | + initLocationClient(); | |
| 556 | 573 | } else { |
| 557 | 574 | EventBus.getDefault().post(new MessageEvent(Constant.START_TRACE_GATHER_FAIL, "")); |
| 558 | 575 | } |
| ... | ... | @@ -613,9 +630,9 @@ public class StepService extends Service implements SensorEventListener { |
| 613 | 630 | } |
| 614 | 631 | |
| 615 | 632 | |
| 616 | - Intent notificationIntent = new Intent(this, PedometerMainActivity.class); | |
| 633 | +// Intent notificationIntent = new Intent(this, PedometerMainActivity.class); | |
| 617 | 634 | notification = new NotificationCompat.Builder(this, CHANNEL_ONE_ID) |
| 618 | - .setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0)) | |
| 635 | +// .setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0)) | |
| 619 | 636 | .setSmallIcon(R.mipmap.ic_launcher) |
| 620 | 637 | // .setCustomContentView(remoteViews) |
| 621 | 638 | .setContentTitle(getResources().getString(R.string.app_name)) |
| ... | ... | @@ -640,6 +657,10 @@ public class StepService extends Service implements SensorEventListener { |
| 640 | 657 | @Override |
| 641 | 658 | public void onDestroy() { |
| 642 | 659 | super.onDestroy(); |
| 660 | + if (null != mLocClient) { | |
| 661 | + mLocClient.stop(); | |
| 662 | + mLocClient = null; | |
| 663 | + } | |
| 643 | 664 | //取消前台进程 |
| 644 | 665 | stopForeground(true); |
| 645 | 666 | if (mBatInfoReceiver != null) { |
| ... | ... | @@ -856,12 +877,12 @@ public class StepService extends Service implements SensorEventListener { |
| 856 | 877 | } else if (Intent.ACTION_DATE_CHANGED.equals(action)) {//日期变化步数重置为0 |
| 857 | 878 | // Logger.d("重置步数" + StepDcretor.CURRENT_STEP); |
| 858 | 879 | save(); |
| 859 | - isNewDay(); | |
| 880 | +// isNewDay(); | |
| 860 | 881 | } else if (Intent.ACTION_TIME_CHANGED.equals(action)) { |
| 861 | 882 | //时间变化步数重置为0 |
| 862 | 883 | // isCall(); |
| 863 | 884 | save(); |
| 864 | - isNewDay(); | |
| 885 | +// isNewDay(); | |
| 865 | 886 | } else if (Intent.ACTION_TIME_TICK.equals(action)) {//日期变化步数重置为0 |
| 866 | 887 | // isCall(); |
| 867 | 888 | // Logger.d("重置步数" + StepDcretor.CURRENT_STEP); |
| ... | ... | @@ -890,10 +911,10 @@ public class StepService extends Service implements SensorEventListener { |
| 890 | 911 | * 监听晚上0点变化初始化数据 |
| 891 | 912 | */ |
| 892 | 913 | private void isNewDay() { |
| 893 | - String time = "00:00"; | |
| 894 | - if (time.equals(new SimpleDateFormat("HH:mm").format(new Date())) || !CURRENT_DATE.equals(getTodayDate())) { | |
| 895 | - initTodayData(userId); | |
| 896 | - } | |
| 914 | +// String time = "00:00"; | |
| 915 | +// if (time.equals(new SimpleDateFormat("HH:mm").format(new Date())) || !CURRENT_DATE.equals(getTodayDate())) { | |
| 916 | +// initTodayData(userId); | |
| 917 | +// } | |
| 897 | 918 | } |
| 898 | 919 | |
| 899 | 920 | // /** |
| ... | ... | @@ -1203,5 +1224,97 @@ public class StepService extends Service implements SensorEventListener { |
| 1203 | 1224 | return String.format("%02d:%02d:%02d", h, m, s); |
| 1204 | 1225 | } |
| 1205 | 1226 | |
| 1227 | + private void initLocationClient() { | |
| 1228 | + if (null == mLocClient) { | |
| 1229 | + // 定位初始化 | |
| 1230 | + mLocClient = new LocationClient(getApplicationContext()); | |
| 1231 | + mLocClient.registerLocationListener(myListener); | |
| 1232 | + } | |
| 1233 | + LocationClientOption option = new LocationClientOption(); | |
| 1234 | + option.setOpenGps(true); // 打开gps | |
| 1235 | + //可选,设置返回经纬度坐标类型,默认GCJ02 | |
| 1236 | + //GCJ02:国测局坐标; | |
| 1237 | + //BD09ll:百度经纬度坐标; | |
| 1238 | + //BD09:百度墨卡托坐标; | |
| 1239 | + //海外地区定位,无需设置坐标类型,统一返回WGS84类型坐标 | |
| 1240 | + option.setCoorType("gcj02"); // 设置坐标类型 | |
| 1241 | + //可选,默认false,设置是否开启Gps定位 | |
| 1242 | + option.setOpenGps(true); | |
| 1243 | + //设置打开自动回调位置模式,该开关打开后,期间只要定位SDK检测到位置变化就会主动回调给开发者,该模式下开发者无需再关心定位间隔是多少,定位SDK本身发现位置变化就会及时回调给开发者 | |
| 1244 | + option.setOpenAutoNotifyMode(); | |
| 1245 | + //可选,默认高精度,设置定位模式,高精度,低功耗,仅设备 | |
| 1246 | + //LocationMode.Hight_Accuracy:高精度; | |
| 1247 | + //LocationMode. Battery_Saving:低功耗; | |
| 1248 | + //LocationMode. Device_Sensors:仅使用设备; | |
| 1249 | + option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); | |
| 1250 | + //可选,设置是否需要地址信息,默认不需要 | |
| 1251 | + option.setIsNeedAddress(false); | |
| 1252 | + //可选,设置是否需要地址描述 | |
| 1253 | + option.setIsNeedLocationDescribe(false); | |
| 1254 | + //可选,设置是否需要设备方向结果 | |
| 1255 | + option.setNeedDeviceDirect(false); | |
| 1256 | + //设置打开自动回调位置模式,该开关打开后,期间只要定位SDK检测到位置变化就会主动回调给开发者 | |
| 1257 | + //minTimeInterval - 最短定位时间间隔,单位毫秒,最小值0,开发者可以在设置希望的位置回调最短时间间隔 | |
| 1258 | + //minDistance - 最短定位距离间隔,单位米,最小值0,开发者可以设置希望的位置回调距离间隔 | |
| 1259 | + //locSensitivity - 定位变化敏感程度,LOC_SENSITIVITY_HIGHT,LOC_SENSITIVITY_MIDDLE,LOC_SENSITIVITY_LOW | |
| 1260 | + option.setOpenAutoNotifyMode(3000, 1, LocationClientOption.LOC_SENSITIVITY_HIGHT); | |
| 1261 | + //可选,定位SDK内部是一个service,并放到了独立进程。 | |
| 1262 | + //设置是否在stop的时候杀死这个进程,默认(建议)不杀死,即setIgnoreKillProcess(true) | |
| 1263 | + option.setIgnoreKillProcess(true); | |
| 1264 | + mLocClient.setLocOption(option); | |
| 1265 | + mLocClient.start(); | |
| 1266 | + } | |
| 1267 | + | |
| 1268 | + /** | |
| 1269 | + * //设置定位监听器,获取到用户当前位置 杨帅 | |
| 1270 | + * 定位SDK监听函数 | |
| 1271 | + */ | |
| 1272 | + public class MyLocationListenner extends BDAbstractLocationListener { | |
| 1206 | 1273 | |
| 1274 | + @Override | |
| 1275 | + public void onReceiveLocation(BDLocation location) { | |
| 1276 | + // map view 销毁后不在处理新接收的位置 | |
| 1277 | + if (location == null || null == getApplicationContext()) { | |
| 1278 | + return; | |
| 1279 | + } | |
| 1280 | + //进行精度过滤 | |
| 1281 | +// if (location.getRadius() > Constant.LOCA_ACCURACY) { | |
| 1282 | +// return; | |
| 1283 | +// } | |
| 1284 | + //进行数据比较(先看看数据库是否有数据) | |
| 1285 | + if (null == endLatLng) { | |
| 1286 | + userStepEntity = StepUtil.getUserStepData(getApplicationContext(), CommonInfo.getUserId(getApplicationContext())); | |
| 1287 | + if (null != userStepEntity) { | |
| 1288 | + if (!TextUtils.isEmpty(userStepEntity.getEndLatLng())) { | |
| 1289 | + endLatLng = GsonUtil.GsonToBean(userStepEntity.getEndLatLng(), LatLng.class); | |
| 1290 | + } | |
| 1291 | + } | |
| 1292 | + } | |
| 1293 | + //开始比较数据 | |
| 1294 | + if (null != endLatLng) { | |
| 1295 | + LatLng current = new LatLng(location.getLatitude(), location.getLongitude()); | |
| 1296 | + if (null != current) { | |
| 1297 | + //开始比较数据 | |
| 1298 | + int distance = (int) DistanceUtil.getDistance(current, endLatLng); | |
| 1299 | + if (distance < Constant.LOCA_END_POINT_ACCURACY) { | |
| 1300 | + if (isHasSendEndTip) { | |
| 1301 | + isHasSendEndTip = false; | |
| 1302 | + Log.e(TAG, "onReceiveLocation: 到达" ); | |
| 1303 | + //发送到达终点通知 | |
| 1304 | + EventBus.getDefault().post(new MessageEvent(Constant.ARRIVE_END_POINT, "")); | |
| 1305 | + } | |
| 1306 | + if (null == userStepEntity) { | |
| 1307 | + userStepEntity = StepUtil.getUserStepData(getApplicationContext(), CommonInfo.getUserId(getApplicationContext())); | |
| 1308 | + } | |
| 1309 | + //设置数据 | |
| 1310 | + if (userStepEntity != null) { | |
| 1311 | + userStepEntity.setIsArriveEndPoint(true); | |
| 1312 | + //更新数据 | |
| 1313 | + StepUtil.updateStepData(getApplicationContext(), userStepEntity); | |
| 1314 | + } | |
| 1315 | + } | |
| 1316 | + } | |
| 1317 | + } | |
| 1318 | + } | |
| 1319 | + } | |
| 1207 | 1320 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/sql/db/DbCore.java
| ... | ... | @@ -62,8 +62,9 @@ public class DbCore { |
| 62 | 62 | if (daoMaster == null) { |
| 63 | 63 | daoMaster = getDaoMaster(); |
| 64 | 64 | } |
| 65 | - //不使用缓存 | |
| 66 | - daoSession = daoMaster.newSession(IdentityScopeType.None); | |
| 65 | +// //不使用缓存 | |
| 66 | +// daoSession = daoMaster.newSession(IdentityScopeType.None); | |
| 67 | + daoSession = daoMaster.newSession(); | |
| 67 | 68 | } |
| 68 | 69 | return daoSession; |
| 69 | 70 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/fragment/RegistrationInfoFragment.java
| ... | ... | @@ -5,7 +5,9 @@ import android.os.Bundle; |
| 5 | 5 | import android.support.annotation.NonNull; |
| 6 | 6 | import android.support.annotation.Nullable; |
| 7 | 7 | import android.text.TextUtils; |
| 8 | +import android.util.Log; | |
| 8 | 9 | import android.view.View; |
| 10 | +import android.widget.Toast; | |
| 9 | 11 | |
| 10 | 12 | import com.baidu.trace.LBSTraceClient; |
| 11 | 13 | import com.baidu.trace.Trace; |
| ... | ... | @@ -30,6 +32,7 @@ import com.cnlive.moudle.pedometer.commonInfo.CommonInfo; |
| 30 | 32 | import com.cnlive.moudle.pedometer.frame.presenter.RegistrationInfoPresenter; |
| 31 | 33 | import com.cnlive.moudle.pedometer.frame.view.RegistrationInfoView; |
| 32 | 34 | import com.cnlive.moudle.pedometer.model.Constant; |
| 35 | +import com.cnlive.moudle.pedometer.utils.NetUtil; | |
| 33 | 36 | import com.cnlive.moudle.pedometer.utils.QMUITipDialogUtil; |
| 34 | 37 | import com.example.moudle_pedometer.R; |
| 35 | 38 | import com.example.moudle_pedometer.databinding.FragmentRegistrationInfoBinding; |
| ... | ... | @@ -69,7 +72,14 @@ public class RegistrationInfoFragment extends MvpBindingFragment<RegistrationInf |
| 69 | 72 | |
| 70 | 73 | public void commitInfo() { |
| 71 | 74 | if (!TextUtils.isEmpty(fenceId)) { |
| 72 | - addMonitorToFence((int) (Double.parseDouble(fenceId))); | |
| 75 | + if (NetUtil.isNetworkConnected(getActivity())) { | |
| 76 | + addMonitorToFence((int) (Double.parseDouble(fenceId))); | |
| 77 | + } else { | |
| 78 | + if (null != getMvpView()) { | |
| 79 | + getMvpView().allowClickRegistBtn(); | |
| 80 | + } | |
| 81 | + AlertUtil.showDeftToast(getActivity(), "无法连接网络"); | |
| 82 | + } | |
| 73 | 83 | } |
| 74 | 84 | } |
| 75 | 85 | |
| ... | ... | @@ -79,7 +89,7 @@ public class RegistrationInfoFragment extends MvpBindingFragment<RegistrationInf |
| 79 | 89 | * @param fenceId |
| 80 | 90 | */ |
| 81 | 91 | public void addMonitorToFence(int fenceId) { |
| 82 | - if (null!=getMvpView()){ | |
| 92 | + if (null != getMvpView()) { | |
| 83 | 93 | getMvpView().limitClickRegistBtn(); |
| 84 | 94 | } |
| 85 | 95 | if (null == getPresenter()) { |
| ... | ... | @@ -148,7 +158,7 @@ public class RegistrationInfoFragment extends MvpBindingFragment<RegistrationInf |
| 148 | 158 | binding.sexText.getText().toString().trim().equals("未选择") ? "" : binding.sexText.getText().toString().trim(), |
| 149 | 159 | binding.birthday.getText().toString().trim().equals("未选择") ? "" : binding.birthday.getText().toString().trim()); |
| 150 | 160 | } else { |
| 151 | - if (null!=getMvpView()){ | |
| 161 | + if (null != getMvpView()) { | |
| 152 | 162 | getMvpView().allowClickRegistBtn(); |
| 153 | 163 | } |
| 154 | 164 | QMUITipDialogUtil.dismessDialog(); |
| ... | ... | @@ -180,6 +190,9 @@ public class RegistrationInfoFragment extends MvpBindingFragment<RegistrationInf |
| 180 | 190 | @Override |
| 181 | 191 | public void onFailed(String msg) { |
| 182 | 192 | QMUITipDialogUtil.dismessDialog(); |
| 193 | + if (null != getMvpView()) { | |
| 194 | + getMvpView().allowClickRegistBtn(); | |
| 195 | + } | |
| 183 | 196 | AlertUtil.showDeftToast(getContext(), msg); |
| 184 | 197 | } |
| 185 | 198 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/fragment/RunMainFragment.java
| ... | ... | @@ -214,6 +214,13 @@ public class RunMainFragment extends QMUIFragment<RunMainFragmentView, RunMainFr |
| 214 | 214 | tipDialog.show(); |
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | + //到达终点 | |
| 218 | + else if (messageEvent.getMessageType() == Constant.ARRIVE_END_POINT) { | |
| 219 | + if (null == getMvpView()) { | |
| 220 | + return; | |
| 221 | + } | |
| 222 | + getMvpView().showEndTipDialog(); | |
| 223 | + } | |
| 217 | 224 | } |
| 218 | 225 | |
| 219 | 226 | @Override | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/fragment/RunningMapFragment.java
| ... | ... | @@ -217,6 +217,13 @@ public class RunningMapFragment extends QMUIFragment<RunningMapFragmentView, Run |
| 217 | 217 | tipDialog.show(); |
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | + //到达终点 | |
| 221 | + else if (messageEvent.getMessageType() == Constant.ARRIVE_END_POINT) { | |
| 222 | + if (null == getMvpView()) { | |
| 223 | + return; | |
| 224 | + } | |
| 225 | + getMvpView().showEndTipDialog(); | |
| 226 | + } | |
| 220 | 227 | } |
| 221 | 228 | |
| 222 | 229 | private void initTipDialog() { | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/MyMapUtil.java
| ... | ... | @@ -69,75 +69,86 @@ public class MyMapUtil { |
| 69 | 69 | * @param geoCodeResult |
| 70 | 70 | */ |
| 71 | 71 | public static void getGeoCoderResult(LatLng latLng, GeoCodeResult geoCodeResult) { |
| 72 | - if (null == latLng) { | |
| 73 | - return; | |
| 74 | - } | |
| 75 | - if (null == mSearch) { | |
| 76 | - mSearch = GeoCoder.newInstance(); | |
| 77 | - } | |
| 78 | - mSearch.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() { | |
| 72 | + try { | |
| 73 | + if (null == latLng) { | |
| 74 | + return; | |
| 75 | + } | |
| 76 | + if (null == mSearch) { | |
| 77 | + mSearch = GeoCoder.newInstance(); | |
| 78 | + } | |
| 79 | + mSearch.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() { | |
| 79 | 80 | |
| 80 | - @Override | |
| 81 | - public void onGetGeoCodeResult(com.baidu.mapapi.search.geocode.GeoCodeResult geoCodeResult) { | |
| 81 | + @Override | |
| 82 | + public void onGetGeoCodeResult(com.baidu.mapapi.search.geocode.GeoCodeResult geoCodeResult) { | |
| 82 | 83 | |
| 83 | - } | |
| 84 | + } | |
| 84 | 85 | |
| 85 | - @Override | |
| 86 | - public void onGetReverseGeoCodeResult(ReverseGeoCodeResult reverseGeoCodeResult) { | |
| 86 | + @Override | |
| 87 | + public void onGetReverseGeoCodeResult(ReverseGeoCodeResult reverseGeoCodeResult) { | |
| 87 | 88 | // Log.e(TAG, "status:" + reverseGeoCodeResult.status + ",error" + reverseGeoCodeResult.error); |
| 88 | - //成功 | |
| 89 | - if (0 == reverseGeoCodeResult.status) { | |
| 90 | - queryGeoCount = 0; | |
| 91 | - if (null != geoCodeResult) { | |
| 92 | - List<PoiInfo> pois = reverseGeoCodeResult.getPoiList(); | |
| 93 | - if (null != pois && pois.size() > 0) { | |
| 94 | - if (!TextUtils.isEmpty(pois.get(0).name)) { | |
| 95 | - geoCodeResult.success(pois.get(0).name); | |
| 96 | - } else { | |
| 97 | - geoCodeResult.success(null); | |
| 98 | - } | |
| 99 | - } else { | |
| 100 | - //如果街道号或者街道为空 | |
| 101 | - if ((null == reverseGeoCodeResult.getAddressDetail().street || TextUtils.isEmpty(reverseGeoCodeResult.getAddressDetail().street)) && (null == reverseGeoCodeResult.getAddressDetail().streetNumber || TextUtils.isEmpty(reverseGeoCodeResult.getAddressDetail().streetNumber))) { | |
| 102 | - if (!TextUtils.isEmpty(reverseGeoCodeResult.getAddress()) && !TextUtils.isEmpty(reverseGeoCodeResult.getSematicDescription())) { | |
| 103 | - geoCodeResult.success(reverseGeoCodeResult.getAddress() + "," + reverseGeoCodeResult.getSematicDescription()); | |
| 104 | - } else if (!TextUtils.isEmpty(reverseGeoCodeResult.getAddress())) { | |
| 105 | - geoCodeResult.success(reverseGeoCodeResult.getAddress()); | |
| 89 | + if (null == reverseGeoCodeResult) { | |
| 90 | + if (null != geoCodeResult) { | |
| 91 | + geoCodeResult.success(null); | |
| 92 | + } | |
| 93 | + } | |
| 94 | + //成功 | |
| 95 | + if (0 == reverseGeoCodeResult.status) { | |
| 96 | + queryGeoCount = 0; | |
| 97 | + if (null != geoCodeResult) { | |
| 98 | + List<PoiInfo> pois = reverseGeoCodeResult.getPoiList(); | |
| 99 | + if (null != pois && pois.size() > 0) { | |
| 100 | + if (!TextUtils.isEmpty(pois.get(0).name)) { | |
| 101 | + geoCodeResult.success(pois.get(0).name); | |
| 106 | 102 | } else { |
| 107 | 103 | geoCodeResult.success(null); |
| 108 | 104 | } |
| 109 | 105 | } else { |
| 110 | - if (!TextUtils.isEmpty(reverseGeoCodeResult.getAddress())) { | |
| 111 | - geoCodeResult.success(reverseGeoCodeResult.getAddress()); | |
| 106 | + //如果街道号或者街道为空 | |
| 107 | + if ((null == reverseGeoCodeResult.getAddressDetail().street || TextUtils.isEmpty(reverseGeoCodeResult.getAddressDetail().street)) && (null == reverseGeoCodeResult.getAddressDetail().streetNumber || TextUtils.isEmpty(reverseGeoCodeResult.getAddressDetail().streetNumber))) { | |
| 108 | + if (!TextUtils.isEmpty(reverseGeoCodeResult.getAddress()) && !TextUtils.isEmpty(reverseGeoCodeResult.getSematicDescription())) { | |
| 109 | + geoCodeResult.success(reverseGeoCodeResult.getAddress() + "," + reverseGeoCodeResult.getSematicDescription()); | |
| 110 | + } else if (!TextUtils.isEmpty(reverseGeoCodeResult.getAddress())) { | |
| 111 | + geoCodeResult.success(reverseGeoCodeResult.getAddress()); | |
| 112 | + } else { | |
| 113 | + geoCodeResult.success(null); | |
| 114 | + } | |
| 112 | 115 | } else { |
| 113 | - geoCodeResult.success(null); | |
| 116 | + if (!TextUtils.isEmpty(reverseGeoCodeResult.getAddress())) { | |
| 117 | + geoCodeResult.success(reverseGeoCodeResult.getAddress()); | |
| 118 | + } else { | |
| 119 | + geoCodeResult.success(null); | |
| 120 | + } | |
| 114 | 121 | } |
| 115 | 122 | } |
| 116 | 123 | } |
| 124 | + } else if (104 == reverseGeoCodeResult.status) { | |
| 125 | + if (0 == queryGeoCount) { | |
| 126 | + queryGeoCount = 1; | |
| 127 | + new Handler().postDelayed(new Runnable() { | |
| 128 | + @Override | |
| 129 | + public void run() { | |
| 130 | + getGeoCoderResult(latLng, geoCodeResult); | |
| 131 | + } | |
| 132 | + }, 1000); | |
| 133 | + } | |
| 117 | 134 | } |
| 118 | - } else if (104 == reverseGeoCodeResult.status) { | |
| 119 | - if (0 == queryGeoCount) { | |
| 120 | - queryGeoCount = 1; | |
| 121 | - new Handler().postDelayed(new Runnable() { | |
| 122 | - @Override | |
| 123 | - public void run() { | |
| 124 | - getGeoCoderResult(latLng, geoCodeResult); | |
| 125 | - } | |
| 126 | - }, 1000); | |
| 127 | - } | |
| 128 | - } | |
| 129 | - //失败 | |
| 130 | - else { | |
| 131 | - queryGeoCount = 0; | |
| 132 | - if (null != geoCodeResult) { | |
| 133 | - geoCodeResult.success(null); | |
| 135 | + //失败 | |
| 136 | + else { | |
| 137 | + queryGeoCount = 0; | |
| 138 | + if (null != geoCodeResult) { | |
| 139 | + geoCodeResult.success(null); | |
| 140 | + } | |
| 134 | 141 | } |
| 135 | 142 | } |
| 143 | + }); | |
| 144 | + mSearch.reverseGeoCode(new ReverseGeoCodeOption() | |
| 145 | + .location(latLng) | |
| 146 | + .radius(Constant.COLL_GEORESULT_RADIUS)); | |
| 147 | + } catch (Exception e) { | |
| 148 | + if (null != geoCodeResult) { | |
| 149 | + geoCodeResult.success(null); | |
| 136 | 150 | } |
| 137 | - }); | |
| 138 | - mSearch.reverseGeoCode(new ReverseGeoCodeOption() | |
| 139 | - .location(latLng) | |
| 140 | - .radius(Constant.COLL_GEORESULT_RADIUS)); | |
| 151 | + } | |
| 141 | 152 | } |
| 142 | 153 | |
| 143 | 154 | /** | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/ScreenUtil.java
| ... | ... | @@ -4,7 +4,9 @@ import android.app.Activity; |
| 4 | 4 | import android.content.Context; |
| 5 | 5 | import android.graphics.Bitmap; |
| 6 | 6 | import android.graphics.Matrix; |
| 7 | +import android.graphics.Point; | |
| 7 | 8 | import android.os.Build; |
| 9 | +import android.view.Display; | |
| 8 | 10 | import android.view.WindowManager; |
| 9 | 11 | |
| 10 | 12 | /*屏幕显示相关设置 |
| ... | ... | @@ -79,6 +81,14 @@ import android.view.WindowManager; |
| 79 | 81 | } |
| 80 | 82 | |
| 81 | 83 | |
| 84 | + public static Point getScreenPoint(Context context) { | |
| 85 | + WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); | |
| 86 | + Display display = manager.getDefaultDisplay(); | |
| 87 | + Point size = new Point(); | |
| 88 | + display.getSize(size); | |
| 89 | + return size; | |
| 90 | + } | |
| 91 | + | |
| 82 | 92 | public static class ScreenInfo { |
| 83 | 93 | private int width; |
| 84 | 94 | private int height; |
| ... | ... | @@ -99,4 +109,5 @@ import android.view.WindowManager; |
| 99 | 109 | this.height = height; |
| 100 | 110 | } |
| 101 | 111 | } |
| 112 | + | |
| 102 | 113 | } | ... | ... |
moudle_pedometer/src/main/res/drawable/shape_load.xml
0 → 100644
moudle_pedometer/src/main/res/layout/fragment_coll_finish_run_map.xml
| ... | ... | @@ -127,5 +127,47 @@ |
| 127 | 127 | android:textColor="@color/white" |
| 128 | 128 | android:textSize="18sp" /> |
| 129 | 129 | </LinearLayout> |
| 130 | + <!--load--> | |
| 131 | + <LinearLayout | |
| 132 | + android:id="@+id/ll_loading" | |
| 133 | + android:layout_width="match_parent" | |
| 134 | + android:layout_height="match_parent" | |
| 135 | + android:focusable="true" | |
| 136 | + android:clickable="true" | |
| 137 | + android:visibility="gone" | |
| 138 | + android:focusableInTouchMode="true" | |
| 139 | + android:gravity="center"> | |
| 140 | + | |
| 141 | + <LinearLayout | |
| 142 | + android:layout_width="wrap_content" | |
| 143 | + android:layout_height="wrap_content" | |
| 144 | + android:layout_gravity="center" | |
| 145 | + android:background="@drawable/shape_load" | |
| 146 | + android:gravity="center" | |
| 147 | + android:orientation="vertical"> | |
| 148 | + | |
| 149 | + <ProgressBar | |
| 150 | + android:layout_width="wrap_content" | |
| 151 | + android:layout_height="wrap_content" | |
| 152 | + android:layout_marginTop="10dp" | |
| 153 | + android:indeterminateTint="@color/white" | |
| 154 | + android:maxWidth="30dp" | |
| 155 | + android:maxHeight="30dp" | |
| 156 | + android:minWidth="20dp" | |
| 157 | + android:minHeight="20dp" | |
| 158 | + android:padding="10dp" /> | |
| 159 | + | |
| 160 | + <TextView | |
| 161 | + android:id="@+id/tv_loading_tip" | |
| 162 | + android:layout_width="wrap_content" | |
| 163 | + android:layout_height="wrap_content" | |
| 164 | + android:layout_marginLeft="15dp" | |
| 165 | + android:layout_marginRight="15dp" | |
| 166 | + android:layout_marginBottom="15dp" | |
| 167 | + android:textSize="13sp" | |
| 168 | + android:text="正在截取赛事图片,请稍后" | |
| 169 | + android:textColor="@color/white" /> | |
| 170 | + </LinearLayout> | |
| 171 | + </LinearLayout> | |
| 130 | 172 | </FrameLayout> |
| 131 | 173 | </layout> |
| 132 | 174 | \ No newline at end of file | ... | ... |
moudle_pedometer/src/main/res/layout/fragment_finish_run_map.xml