Commit 18c99e745c690cbc121c2eb11e8334cdd3de82bf
Merge branch 'master' of bj.gitlab.cnlive.com:cnlive-team/ModulePedometer
Showing
6 changed files
with
76 additions
and
22 deletions
app/build.gradle
| ... | ... | @@ -28,17 +28,23 @@ android { |
| 28 | 28 | buildConfigField("String", "APP_ID", stringValue("802_jhbqccxw08")) |
| 29 | 29 | buildConfigField("String", "APP_KEY", stringValue("9c5619e9be747bb3b925dd215ca5923d86f12c09b9394f")) |
| 30 | 30 | buildConfigField("String", "APP_SCERET", stringValue("1e6380cb347255e777f72b5aa60f41daa68443a132aaea")) |
| 31 | + // BAIDU_MAP_APP_KEY : "2IIsTtvX2FA88yvDrPZedc2ZvMhxyDbN" | |
| 31 | 32 | manifestPlaceholders = [ |
| 32 | - BAIDU_MAP_APP_KEY : "2IIsTtvX2FA88yvDrPZedc2ZvMhxyDbN" | |
| 33 | + | |
| 34 | + BAIDU_MAP_APP_KEY: "OeotXc38bbnU7WmyKGA0VMahk4v35VG2" | |
| 35 | + | |
| 36 | + | |
| 33 | 37 | ] |
| 34 | 38 | } |
| 39 | +// BAIDU_MAP_APP_KEY: "Q7y9SGcZVs0tmhbNTiaz0jHm4S1xGzE2" | |
| 40 | + | |
| 35 | 41 | release { |
| 36 | 42 | resValue("string", "app_name", "网++") |
| 37 | 43 | buildConfigField("String", "APP_ID", stringValue("769_jetj7bq525")) |
| 38 | 44 | buildConfigField("String", "APP_KEY", stringValue("0d57b045ec0c3988a682d94c644e66b9b8e0d2b8ef937d")) |
| 39 | 45 | buildConfigField("String", "APP_SCERET", stringValue("275e8dc29274a1186d82f65bc607c231d02bcb3bfd8976")) |
| 40 | 46 | manifestPlaceholders = [ |
| 41 | - BAIDU_MAP_APP_KEY : "Q7y9SGcZVs0tmhbNTiaz0jHm4S1xGzE2" | |
| 47 | + BAIDU_MAP_APP_KEY: "0bWeo04KKKHqTwozcqgyLZVd0oVhv3rZ" | |
| 42 | 48 | ] |
| 43 | 49 | } |
| 44 | 50 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/presenter/RunningMapFragmentPresenter.java
| ... | ... | @@ -19,6 +19,7 @@ import com.baidu.trace.api.track.LatestPointResponse; |
| 19 | 19 | import com.baidu.trace.api.track.OnTrackListener; |
| 20 | 20 | import com.baidu.trace.api.track.SupplementMode; |
| 21 | 21 | import com.baidu.trace.api.track.TrackPoint; |
| 22 | +import com.baidu.trace.model.CoordType; | |
| 22 | 23 | import com.baidu.trace.model.ProcessOption; |
| 23 | 24 | import com.baidu.trace.model.SortType; |
| 24 | 25 | import com.baidu.trace.model.StatusCodes; |
| ... | ... | @@ -60,9 +61,10 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag |
| 60 | 61 | * @param endTime |
| 61 | 62 | */ |
| 62 | 63 | public void queryHistoryTrace(Context context, String entityName, long startTime, long endTime) { |
| 63 | - Log.e(TAG, "queryHistoryTrace: "); | |
| 64 | 64 | if (historyTrackRequest == null) { |
| 65 | - historyTrackRequest = new HistoryTrackRequest(); | |
| 65 | + Log.e(TAG, "queryHistoryTrace: StepService.serviceId" + StepService.serviceId + ",entityName:" + entityName); | |
| 66 | + Log.e(TAG, "queryHistoryTrace: startTime:" + startTime + ",endTime:" + endTime); | |
| 67 | + historyTrackRequest = new HistoryTrackRequest(1, StepService.serviceId, entityName); | |
| 66 | 68 | //设置查询设备名称 |
| 67 | 69 | historyTrackRequest.setEntityName(entityName); |
| 68 | 70 | //历史轨迹开始时间 |
| ... | ... | @@ -75,6 +77,8 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag |
| 75 | 77 | historyTrackRequest.setPageSize(pageSize); |
| 76 | 78 | //设置是否进行纠偏 |
| 77 | 79 | historyTrackRequest.setProcessed(true); |
| 80 | + //设置返回坐标系 | |
| 81 | + historyTrackRequest.setCoordTypeOutput(CoordType.gcj02); | |
| 78 | 82 | //其他设置 |
| 79 | 83 | ProcessOption processOption = new ProcessOption(); |
| 80 | 84 | //去噪:可设置是否需要去除角度、速度和方向异常的轨迹点 |
| ... | ... | @@ -84,9 +88,9 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag |
| 84 | 88 | //抽稀:设置是否进行抽稀处理,对冗余的轨迹点进行抽稀去除处理,如一条直线上除起终点外的多个轨迹点 |
| 85 | 89 | processOption.setNeedVacuate(true); |
| 86 | 90 | //自动判断交通方式 |
| 87 | - processOption.setTransportMode(TransportMode.auto); | |
| 91 | + processOption.setTransportMode(TransportMode.walking); | |
| 88 | 92 | // 设置精度过滤值(定位精度大于100米的过滤掉) |
| 89 | - processOption.setRadiusThreshold(100); | |
| 93 | + processOption.setRadiusThreshold(20); | |
| 90 | 94 | // 设置纠偏选项 |
| 91 | 95 | historyTrackRequest.setProcessOption(processOption); |
| 92 | 96 | // 设置里程填充方式为驾车 |
| ... | ... | @@ -102,7 +106,10 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag |
| 102 | 106 | public void onHistoryTrackCallback(HistoryTrackResponse response) { |
| 103 | 107 | super.onHistoryTrackCallback(response); |
| 104 | 108 | int total = response.getTotal(); |
| 109 | + Log.e(TAG, "onHistoryTrackCallback: total" + total + "数量"); | |
| 110 | + | |
| 105 | 111 | if (StatusCodes.SUCCESS != response.getStatus()) { |
| 112 | + Toast.makeText(context, "获取轨迹失败!" + response.getStatus(), Toast.LENGTH_SHORT).show(); | |
| 106 | 113 | } else if (0 == total) { |
| 107 | 114 | Toast.makeText(context, "暂未查到您的轨迹,请稍后重试!", Toast.LENGTH_SHORT).show(); |
| 108 | 115 | } else { |
| ... | ... | @@ -123,7 +130,7 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag |
| 123 | 130 | queryHistoryTrace(context, entityName, startTime, endTime); |
| 124 | 131 | } else { |
| 125 | 132 | if (getView() != null) { |
| 126 | - MyMapUtil.drawHistoryTrack(context, getView().baiduMap, trackPoints, SortType.asc, R.color.red, R.drawable.icon_start, R.drawable.run_map_icon_end); | |
| 133 | + MyMapUtil.drawHistoryTrack(context, getView().baiduMap, trackPoints, SortType.asc, R.color.red, R.drawable.icon_start, R.drawable.icon_end); | |
| 127 | 134 | } |
| 128 | 135 | } |
| 129 | 136 | } |
| ... | ... | @@ -131,15 +138,17 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag |
| 131 | 138 | @Override |
| 132 | 139 | public void onLatestPointCallback(LatestPointResponse latestPointResponse) { |
| 133 | 140 | super.onLatestPointCallback(latestPointResponse); |
| 134 | - if (StatusCodes.SUCCESS != latestPointResponse.getStatus()) { | |
| 135 | - } else { | |
| 136 | - Bitmap startPointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), R.drawable.run_map_icon_start), 40, 40); | |
| 137 | - OverlayOptions startOptions = new MarkerOptions() | |
| 138 | - .position(MyMapUtil.convertTrace2Map(latestPointResponse.getLatestPoint().getLocation())).icon(BitmapDescriptorFactory.fromBitmap(startPointBitmap)); | |
| 139 | - if (getView() != null) { | |
| 140 | - getView().baiduMap.addOverlay(startOptions); | |
| 141 | - } | |
| 142 | - } | |
| 141 | + Log.e(TAG, "onLatestPointCallback: "); | |
| 142 | + | |
| 143 | +// if (StatusCodes.SUCCESS != latestPointResponse.getStatus()) { | |
| 144 | +// } else { | |
| 145 | +// Bitmap startPointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), R.drawable.run_map_icon_start), 40, 40); | |
| 146 | +// OverlayOptions startOptions = new MarkerOptions() | |
| 147 | +// .position(MyMapUtil.convertTrace2Map(latestPointResponse.getLatestPoint().getLocation())).icon(BitmapDescriptorFactory.fromBitmap(startPointBitmap)); | |
| 148 | +// if (getView() != null) { | |
| 149 | +// getView().baiduMap.addOverlay(startOptions); | |
| 150 | +// } | |
| 151 | +// } | |
| 143 | 152 | } |
| 144 | 153 | }; |
| 145 | 154 | //开始查询历史轨迹 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunMainFragmentView.java
| ... | ... | @@ -19,6 +19,7 @@ import com.cnlive.moudle.pedometer.ui.activity.RunningMapActivity; |
| 19 | 19 | import com.cnlive.moudle.pedometer.ui.fragment.RunMainFragment; |
| 20 | 20 | import com.cnlive.moudle.pedometer.ui.widget.SelectDialog; |
| 21 | 21 | import com.cnlive.moudle.pedometer.utils.ButtonAnimUtil; |
| 22 | +import com.cnlive.moudle.pedometer.utils.MySpHelper; | |
| 22 | 23 | import com.cnlive.moudle.pedometer.utils.StepUtil; |
| 23 | 24 | import com.example.moudle_pedometer.R; |
| 24 | 25 | import com.hannesdorfmann.mosby3.mvp.MvpView; |
| ... | ... | @@ -172,6 +173,10 @@ public class RunMainFragmentView implements MvpView { |
| 172 | 173 | fragment.binding.flContinue.setOnClickListener(new View.OnClickListener() { |
| 173 | 174 | @Override |
| 174 | 175 | public void onClick(View view) { |
| 176 | + //继续记录轨迹 | |
| 177 | + if (StepService.mClient != null && StepService.traceListener != null) { | |
| 178 | + StepService.mClient.startGather(StepService.traceListener); | |
| 179 | + } | |
| 175 | 180 | needWriteDataFlag = true; |
| 176 | 181 | //将当前计时器时间戳写入数据库 |
| 177 | 182 | setSQLPauseTime(); |
| ... | ... | @@ -237,14 +242,16 @@ public class RunMainFragmentView implements MvpView { |
| 237 | 242 | public void onClick(SelectDialog dialog) { |
| 238 | 243 | fragment.binding.cpCurrent.setVisibility(View.GONE); |
| 239 | 244 | ButtonAnimUtil.setViewDefault(fragment.binding.flStop); |
| 240 | - fragment.getActivity().stopService(new Intent(fragment.getActivity(), StepService.class)); | |
| 241 | 245 | //清空数据 |
| 242 | 246 | StepUtil.clearRunData(getContext(), uid); |
| 243 | 247 | dialog.dismiss(); |
| 244 | 248 | if (StepService.mClient != null) { |
| 245 | 249 | StepService.mClient.stopGather(StepService.traceListener); |
| 246 | 250 | } |
| 247 | -// fragment.getActivity().finish(); | |
| 251 | + MySpHelper.getInstance(getContext(), Context.MODE_MULTI_PROCESS).putLong("stepStartTime", 0); | |
| 252 | + fragment.getActivity().stopService(new Intent(fragment.getActivity(), StepService.class)); | |
| 253 | + | |
| 254 | + // fragment.getActivity().finish(); | |
| 248 | 255 | } |
| 249 | 256 | }, "取消", new SelectDialog.DialogInterface() { |
| 250 | 257 | @Override |
| ... | ... | @@ -296,6 +303,10 @@ public class RunMainFragmentView implements MvpView { |
| 296 | 303 | fragment.binding.flPause.setOnClickListener(new View.OnClickListener() { |
| 297 | 304 | @Override |
| 298 | 305 | public void onClick(View view) { |
| 306 | + //暂停轨迹记录 | |
| 307 | + if (StepService.mClient != null && StepService.traceListener != null) { | |
| 308 | + StepService.mClient.stopGather(StepService.traceListener); | |
| 309 | + } | |
| 299 | 310 | //将当前计时器时间戳写入数据库 |
| 300 | 311 | setSQLPauseTime(); |
| 301 | 312 | needWriteDataFlag = false; | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/service/StepService.java
| ... | ... | @@ -47,6 +47,8 @@ import com.cnlive.moudle.pedometer.sql.dao.UserStepEntityDao; |
| 47 | 47 | import com.cnlive.moudle.pedometer.sql.db.DbCore; |
| 48 | 48 | import com.cnlive.moudle.pedometer.sql.entity.UserStepEntity; |
| 49 | 49 | import com.cnlive.moudle.pedometer.ui.activity.PedometerMainActivity; |
| 50 | +import com.cnlive.moudle.pedometer.utils.MySpHelper; | |
| 51 | +import com.cnlive.moudle.pedometer.utils.TimeUtil; | |
| 50 | 52 | import com.example.moudle_pedometer.R; |
| 51 | 53 | import com.orhanobut.logger.Logger; |
| 52 | 54 | |
| ... | ... | @@ -144,7 +146,10 @@ public class StepService extends Service implements SensorEventListener { |
| 144 | 146 | //打包周期 |
| 145 | 147 | private int packInterval = 30; |
| 146 | 148 | // 轨迹服务ID |
| 147 | - public static final long serviceId = 213511; | |
| 149 | +// public static final long serviceId = 213511; | |
| 150 | +//杨帅 | |
| 151 | + public static final long serviceId = 213553; | |
| 152 | + | |
| 148 | 153 | // 设备标识 |
| 149 | 154 | public static String entityName = ""; |
| 150 | 155 | /** |
| ... | ... | @@ -174,9 +179,12 @@ public class StepService extends Service implements SensorEventListener { |
| 174 | 179 | private void initTrace() { |
| 175 | 180 | if (mClient == null) { |
| 176 | 181 | mClient = new LBSTraceClient(getApplicationContext()); |
| 182 | + // 设置定位和打包周期 | |
| 183 | + mClient.setInterval(gatherInterval, packInterval); | |
| 177 | 184 | } |
| 178 | 185 | if (mTrace == null) { |
| 179 | 186 | mTrace = new Trace(serviceId, entityName); |
| 187 | + | |
| 180 | 188 | } |
| 181 | 189 | //初始化实时轨迹监听器 |
| 182 | 190 | realTimeTraceListener = new OnTrackListener() { |
| ... | ... | @@ -324,6 +332,10 @@ public class StepService extends Service implements SensorEventListener { |
| 324 | 332 | //开启轨迹服务 |
| 325 | 333 | if (mClient != null) { |
| 326 | 334 | mClient.startTrace(mTrace, traceListener); |
| 335 | + long stepStartTime = MySpHelper.getInstance(getApplicationContext(), Context.MODE_MULTI_PROCESS).getLong("stepStartTime", 0); | |
| 336 | + if (stepStartTime == 0) { | |
| 337 | + MySpHelper.getInstance(getApplicationContext(), Context.MODE_MULTI_PROCESS).putLong("stepStartTime", TimeUtil.getCurrentTime()); | |
| 338 | + } | |
| 327 | 339 | } |
| 328 | 340 | |
| 329 | 341 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/fragment/RunningMapFragment.java
| 1 | 1 | package com.cnlive.moudle.pedometer.ui.fragment; |
| 2 | 2 | |
| 3 | +import android.content.Context; | |
| 3 | 4 | import android.hardware.Sensor; |
| 4 | 5 | import android.hardware.SensorManager; |
| 5 | 6 | import android.os.Bundle; |
| 7 | +import android.os.SystemClock; | |
| 6 | 8 | import android.support.annotation.Nullable; |
| 7 | 9 | import android.text.TextUtils; |
| 8 | 10 | import android.util.Log; |
| ... | ... | @@ -16,6 +18,7 @@ import com.cnlive.moudle.pedometer.model.RunningMapBean; |
| 16 | 18 | import com.cnlive.moudle.pedometer.model.Constant; |
| 17 | 19 | import com.cnlive.moudle.pedometer.model.MessageEvent; |
| 18 | 20 | import com.cnlive.moudle.pedometer.service.StepService; |
| 21 | +import com.cnlive.moudle.pedometer.utils.MySpHelper; | |
| 19 | 22 | import com.cnlive.moudle.pedometer.utils.TimeUtil; |
| 20 | 23 | import com.example.moudle_pedometer.R; |
| 21 | 24 | import com.example.moudle_pedometer.databinding.FragmentRunningMapBinding; |
| ... | ... | @@ -83,8 +86,21 @@ public class RunningMapFragment extends QMUIFragment<RunningMapFragmentView, Run |
| 83 | 86 | } |
| 84 | 87 | //开始进行历史轨迹查询 |
| 85 | 88 | if (getPresenter() != null && !TextUtils.isEmpty(StepService.entityName)) { |
| 86 | - long startTime = runningMapBean.getTimeBase(); | |
| 87 | - long endTime = TimeUtil.getCurrentTime(); | |
| 89 | + long stepStartTime = MySpHelper.getInstance(getActivity(), Context.MODE_MULTI_PROCESS).getLong("stepStartTime", 0); | |
| 90 | + long startTime = 0; | |
| 91 | + if (stepStartTime != 0) { | |
| 92 | + startTime = stepStartTime; | |
| 93 | + } else { | |
| 94 | + startTime = (int) (System.currentTimeMillis() / 1000 - 12 * 60 * 60); | |
| 95 | + } | |
| 96 | +// long base = runningMapBean.getTimeBase() + (SystemClock.elapsedRealtime() - runningMapBean.getRecordTime()); | |
| 97 | +// int hour = (int) ((SystemClock.elapsedRealtime() - base) / 1000 / 60 / 60); | |
| 98 | +// int minute = (int) ((SystemClock.elapsedRealtime() - base) / 1000 / 60) % 60; | |
| 99 | +// int second = (int) ((SystemClock.elapsedRealtime() - base) / 1000) % 60; | |
| 100 | + long current = TimeUtil.getCurrentTime(); | |
| 101 | +// long startTime = current - hour * 3600 * 1000 - minute * 60 * 1000 - second * 1000; | |
| 102 | + long endTime = current; | |
| 103 | +// Log.e(TAG, "onViewCreated: " + "hour:" + hour + ",minute" + minute + ",second:" + second); | |
| 88 | 104 | getPresenter().queryHistoryTrace(getActivity(), StepService.entityName, startTime, endTime); |
| 89 | 105 | } |
| 90 | 106 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/MyMapUtil.java
| ... | ... | @@ -75,7 +75,7 @@ public class MyMapUtil { |
| 75 | 75 | .color(context.getResources().getColor(lineColor)).points(points); |
| 76 | 76 | |
| 77 | 77 | baiduMap.addOverlay(startOptions); |
| 78 | -// baiduMap.addOverlay(endOptions); | |
| 78 | + baiduMap.addOverlay(endOptions); | |
| 79 | 79 | return baiduMap.addOverlay(polylineOptions); |
| 80 | 80 | } |
| 81 | 81 | } | ... | ... |