Commit bf3f5578db96fafe02044e4bc9f499b178e142fa
1 parent
9df709a2
1.;跑步结束页面
Showing
25 changed files
with
543 additions
and
204 deletions
app/build.gradle
| ... | ... | @@ -28,15 +28,16 @@ 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 | +// BAIDU_MAP_APP_KEY: "OeotXc38bbnU7WmyKGA0VMahk4v35VG2" | |
| 32 | 32 | manifestPlaceholders = [ |
| 33 | 33 | |
| 34 | - BAIDU_MAP_APP_KEY: "OeotXc38bbnU7WmyKGA0VMahk4v35VG2" | |
| 34 | + BAIDU_MAP_APP_KEY: "2IIsTtvX2FA88yvDrPZedc2ZvMhxyDbN" | |
| 35 | 35 | |
| 36 | 36 | |
| 37 | 37 | ] |
| 38 | 38 | } |
| 39 | 39 | // BAIDU_MAP_APP_KEY: "Q7y9SGcZVs0tmhbNTiaz0jHm4S1xGzE2" |
| 40 | +// BAIDU_MAP_APP_KEY: "0bWeo04KKKHqTwozcqgyLZVd0oVhv3rZ" | |
| 40 | 41 | |
| 41 | 42 | release { |
| 42 | 43 | resValue("string", "app_name", "网++") |
| ... | ... | @@ -44,7 +45,7 @@ android { |
| 44 | 45 | buildConfigField("String", "APP_KEY", stringValue("0d57b045ec0c3988a682d94c644e66b9b8e0d2b8ef937d")) |
| 45 | 46 | buildConfigField("String", "APP_SCERET", stringValue("275e8dc29274a1186d82f65bc607c231d02bcb3bfd8976")) |
| 46 | 47 | manifestPlaceholders = [ |
| 47 | - BAIDU_MAP_APP_KEY: "0bWeo04KKKHqTwozcqgyLZVd0oVhv3rZ" | |
| 48 | + BAIDU_MAP_APP_KEY: "Q7y9SGcZVs0tmhbNTiaz0jHm4S1xGzE2" | |
| 48 | 49 | ] |
| 49 | 50 | } |
| 50 | 51 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/presenter/RunningMapFragmentPresenter.java
| ... | ... | @@ -59,6 +59,7 @@ import com.baidu.trace.model.TraceLocation; |
| 59 | 59 | import com.baidu.trace.model.TransportMode; |
| 60 | 60 | import com.cnlive.moudle.pedometer.frame.view.RunningMapFragmentView; |
| 61 | 61 | import com.cnlive.moudle.pedometer.model.Constant; |
| 62 | +import com.cnlive.moudle.pedometer.model.RoutePoint; | |
| 62 | 63 | import com.cnlive.moudle.pedometer.service.StepService; |
| 63 | 64 | import com.cnlive.moudle.pedometer.utils.BitmapUtil; |
| 64 | 65 | import com.cnlive.moudle.pedometer.utils.CommonUtil; |
| ... | ... | @@ -127,9 +128,9 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag |
| 127 | 128 | //去噪:可设置是否需要去除角度、速度和方向异常的轨迹点 |
| 128 | 129 | processOption.setNeedDenoise(true); |
| 129 | 130 | //绑路:设置是否将轨迹点绑定至路网道路 |
| 130 | - processOption.setNeedMapMatch(true); | |
| 131 | + processOption.setNeedMapMatch(false); | |
| 131 | 132 | //抽稀:设置是否进行抽稀处理,对冗余的轨迹点进行抽稀去除处理,如一条直线上除起终点外的多个轨迹点 |
| 132 | -// processOption.setNeedVacuate(true); | |
| 133 | + processOption.setNeedVacuate(true); | |
| 133 | 134 | //自动判断交通方式 |
| 134 | 135 | processOption.setTransportMode(TransportMode.walking); |
| 135 | 136 | // 设置精度过滤值(定位精度大于100米的过滤掉) |
| ... | ... | @@ -172,14 +173,12 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag |
| 172 | 173 | queryHistoryTrace(context, entityName, startTime, endTime); |
| 173 | 174 | } else { |
| 174 | 175 | if (getView() != null) { |
| 175 | - List<com.baidu.trace.model.LatLng> fenceLatLngs = new ArrayList<>(); | |
| 176 | -// for (LatLng latLng:trackPoints){ | |
| 177 | -// com.baidu.trace.model.LatLng tempLatLng=new com.baidu.trace.model.LatLng(latLng.latitude,latLng.longitude); | |
| 178 | -// fenceLatLngs.add(tempLatLng); | |
| 179 | -// } | |
| 180 | -// Log.e(TAG, "onHistoryTrackCallback: "+trackPoints.size()+","+ GsonUtil.GsonString(trackPoints)); | |
| 181 | -// createFence(context, fenceLatLngs); | |
| 176 | + List<RoutePoint> routePoints = new ArrayList<>(); | |
| 177 | + for (LatLng latLng : trackPoints) { | |
| 178 | + routePoints.add(new RoutePoint(latLng.latitude, latLng.longitude)); | |
| 179 | + } | |
| 182 | 180 | MyMapUtil.drawHistoryTrack(context, getView().baiduMap, trackPoints, SortType.asc, R.color.red, R.drawable.icon_start, R.drawable.icon_end); |
| 181 | +// MyMapUtil.drawMapLineRoutePoint(context, getView().baiduMap, MyMapUtil.optimizePoints(routePoints), R.color.red); | |
| 183 | 182 | } |
| 184 | 183 | } |
| 185 | 184 | } |
| ... | ... | @@ -335,9 +334,13 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag |
| 335 | 334 | // 监控状态回调 |
| 336 | 335 | @Override |
| 337 | 336 | public void onMonitoredStatusCallback(MonitoredStatusResponse monitoredStatusResponse) { |
| 338 | - Toast.makeText(context, "围栏列表回调成功:onMonitoredStatusCallback", Toast.LENGTH_SHORT).show(); | |
| 339 | - //查询监控对象状态响应结果 | |
| 337 | + if (monitoredStatusResponse.getMonitoredStatusInfos() != null) { | |
| 338 | + Toast.makeText(context, "围栏列表回调成功:个数:" + monitoredStatusResponse.getMonitoredStatusInfos().size(), Toast.LENGTH_SHORT).show(); | |
| 339 | + } //查询监控对象状态响应结果 | |
| 340 | 340 | List<MonitoredStatusInfo> monitoredStatusInfos = monitoredStatusResponse.getMonitoredStatusInfos(); |
| 341 | + if (monitoredStatusInfos == null) { | |
| 342 | + return; | |
| 343 | + } | |
| 341 | 344 | for (MonitoredStatusInfo monitoredStatusInfo : monitoredStatusInfos) { |
| 342 | 345 | monitoredStatusInfo.getFenceId(); |
| 343 | 346 | MonitoredStatus status = monitoredStatusInfo.getMonitoredStatus();//获取状态 |
| ... | ... | @@ -406,7 +409,7 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag |
| 406 | 409 | } |
| 407 | 410 | |
| 408 | 411 | List<Long> fenid = new ArrayList<>(); |
| 409 | - fenid.add(111L); | |
| 412 | + fenid.add(1L); | |
| 410 | 413 | MonitoredStatusRequest request1 = MonitoredStatusRequest.buildServerRequest(1, |
| 411 | 414 | StepService.serviceId, "yangshuai", fenid); |
| 412 | 415 | Handler handler = new Handler(); |
| ... | ... | @@ -414,7 +417,6 @@ public class RunningMapFragmentPresenter extends MvpBasePresenter<RunningMapFrag |
| 414 | 417 | @Override |
| 415 | 418 | public void run() { |
| 416 | 419 | StepService.mClient.queryMonitoredStatus(request1, onFenceListener); |
| 417 | -// handler.postDelayed(this, 5000); | |
| 418 | 420 | } |
| 419 | 421 | }; |
| 420 | 422 | handler.postDelayed(runnable, 5000); | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunMainFragmentView.java
| ... | ... | @@ -75,6 +75,9 @@ public class RunMainFragmentView implements MvpView { |
| 75 | 75 | runnable = new Runnable() { |
| 76 | 76 | @Override |
| 77 | 77 | public void run() { |
| 78 | + if (fragment.getActivity() == null) { | |
| 79 | + return; | |
| 80 | + } | |
| 78 | 81 | if (timeCountDown > 1) { |
| 79 | 82 | timeCountDown--; |
| 80 | 83 | fragment.binding.tvTimeCountDown.setVisibility(View.VISIBLE); |
| ... | ... | @@ -257,7 +260,7 @@ public class RunMainFragmentView implements MvpView { |
| 257 | 260 | fragment.getActivity().stopService(new Intent(fragment.getActivity(), StepService.class)); |
| 258 | 261 | MySpHelper.getInstance(getContext(), Context.MODE_MULTI_PROCESS).putString("userId", ""); |
| 259 | 262 | RunningFinishActivity.startActivity(fragment.getActivity()); |
| 260 | - // fragment.getActivity().finish(); | |
| 263 | + fragment.getActivity().finish(); | |
| 261 | 264 | } |
| 262 | 265 | }, "取消", new SelectDialog.DialogInterface() { |
| 263 | 266 | @Override | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunningMapFragmentView.java
| ... | ... | @@ -28,8 +28,11 @@ import com.baidu.mapapi.map.MapView; |
| 28 | 28 | import com.baidu.mapapi.map.MarkerOptions; |
| 29 | 29 | import com.baidu.mapapi.map.MyLocationConfiguration; |
| 30 | 30 | import com.baidu.mapapi.map.MyLocationData; |
| 31 | +import com.baidu.mapapi.map.Overlay; | |
| 31 | 32 | import com.baidu.mapapi.map.UiSettings; |
| 32 | 33 | import com.baidu.mapapi.model.LatLng; |
| 34 | +import com.baidu.mapapi.utils.DistanceUtil; | |
| 35 | +import com.baidu.trace.model.SortType; | |
| 33 | 36 | import com.cnlive.moudle.pedometer.model.RunningMapBean; |
| 34 | 37 | import com.cnlive.moudle.pedometer.ui.fragment.RunningMapFragment; |
| 35 | 38 | import com.cnlive.moudle.pedometer.utils.BitmapUtil; |
| ... | ... | @@ -39,6 +42,7 @@ import com.cnlive.moudle.pedometer.utils.StepUtil; |
| 39 | 42 | import com.example.moudle_pedometer.R; |
| 40 | 43 | import com.hannesdorfmann.mosby3.mvp.MvpView; |
| 41 | 44 | |
| 45 | +import java.util.ArrayList; | |
| 42 | 46 | import java.util.List; |
| 43 | 47 | |
| 44 | 48 | public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| ... | ... | @@ -54,7 +58,7 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 54 | 58 | private static MyLocationData mylocation; |
| 55 | 59 | boolean isFirstLoc = true; // 是否首次定位 |
| 56 | 60 | private MarkerOptions currentMark; |
| 57 | - private LatLng firstLatLng; | |
| 61 | + private LatLng myCurLatLng; | |
| 58 | 62 | private Double lastX = 0.0; |
| 59 | 63 | private int mCurrentDirection = 0; |
| 60 | 64 | private double mCurrentLat = 0.0; |
| ... | ... | @@ -66,6 +70,8 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 66 | 70 | private final int DEFULT_ZOOM = 17; |
| 67 | 71 | private boolean isFirstLoadMap = true; |
| 68 | 72 | private List<LatLng> trackPoints; |
| 73 | + private Overlay currentLine; | |
| 74 | + private List<LatLng> currentPoints; | |
| 69 | 75 | |
| 70 | 76 | public RunningMapFragmentView(RunningMapFragment fragment) { |
| 71 | 77 | this.fragment = fragment; |
| ... | ... | @@ -76,6 +82,7 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 76 | 82 | } |
| 77 | 83 | |
| 78 | 84 | public void initView(List<LatLng> trackPoints) { |
| 85 | + currentPoints = new ArrayList<>(); | |
| 79 | 86 | this.trackPoints = trackPoints; |
| 80 | 87 | this.mMapView = fragment.binding.mapView; |
| 81 | 88 | if (baiduMap == null) { |
| ... | ... | @@ -103,7 +110,7 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 103 | 110 | mMapView.showZoomControls(false); |
| 104 | 111 | mUiSettings.setEnlargeCenterWithDoubleClickEnable(true); |
| 105 | 112 | //隐藏自带的指南针,改用自定义指南针 杨帅 |
| 106 | - baiduMap.getUiSettings().setCompassEnabled(true); | |
| 113 | + mUiSettings.setCompassEnabled(false); | |
| 107 | 114 | //显示定位图层 |
| 108 | 115 | baiduMap.setMyLocationEnabled(true); |
| 109 | 116 | // 定位初始化 |
| ... | ... | @@ -111,21 +118,36 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 111 | 118 | mLocClient.registerLocationListener(myListener); |
| 112 | 119 | LocationClientOption option = new LocationClientOption(); |
| 113 | 120 | option.setOpenGps(true); // 打开gps |
| 121 | + //可选,设置返回经纬度坐标类型,默认GCJ02 | |
| 122 | + //GCJ02:国测局坐标; | |
| 123 | + //BD09ll:百度经纬度坐标; | |
| 124 | + //BD09:百度墨卡托坐标; | |
| 125 | + //海外地区定位,无需设置坐标类型,统一返回WGS84类型坐标 | |
| 114 | 126 | option.setCoorType("gcj02"); // 设置坐标类型 |
| 115 | 127 | //可选,默认false,设置是否开启Gps定位 |
| 116 | 128 | option.setOpenGps(true); |
| 117 | 129 | //设置打开自动回调位置模式,该开关打开后,期间只要定位SDK检测到位置变化就会主动回调给开发者,该模式下开发者无需再关心定位间隔是多少,定位SDK本身发现位置变化就会及时回调给开发者 |
| 118 | 130 | option.setOpenAutoNotifyMode(); |
| 119 | 131 | //可选,默认高精度,设置定位模式,高精度,低功耗,仅设备 |
| 132 | + //LocationMode.Hight_Accuracy:高精度; | |
| 133 | + //LocationMode. Battery_Saving:低功耗; | |
| 134 | + //LocationMode. Device_Sensors:仅使用设备; | |
| 120 | 135 | option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); |
| 121 | 136 | //可选,设置是否需要地址信息,默认不需要 |
| 122 | - option.setIsNeedAddress(true); | |
| 137 | + option.setIsNeedAddress(false); | |
| 123 | 138 | //可选,设置是否需要地址描述 |
| 124 | - option.setIsNeedLocationDescribe(true); | |
| 139 | + option.setIsNeedLocationDescribe(false); | |
| 125 | 140 | //可选,设置是否需要设备方向结果 |
| 126 | 141 | option.setNeedDeviceDirect(false); |
| 127 | 142 | //设置打开自动回调位置模式,该开关打开后,期间只要定位SDK检测到位置变化就会主动回调给开发者 |
| 143 | + //minTimeInterval - 最短定位时间间隔,单位毫秒,最小值0,开发者可以在设置希望的位置回调最短时间间隔 | |
| 144 | + //minDistance - 最短定位距离间隔,单位米,最小值0,开发者可以设置希望的位置回调距离间隔 | |
| 145 | + //locSensitivity - 定位变化敏感程度,LOC_SENSITIVITY_HIGHT,LOC_SENSITIVITY_MIDDLE,LOC_SENSITIVITY_LOW | |
| 128 | 146 | option.setOpenAutoNotifyMode(3000, 1, LocationClientOption.LOC_SENSITIVITY_HIGHT); |
| 147 | + //可选,定位SDK内部是一个service,并放到了独立进程。 | |
| 148 | + //设置是否在stop的时候杀死这个进程,默认(建议)不杀死,即setIgnoreKillProcess(true) | |
| 149 | + option.setIgnoreKillProcess(true); | |
| 150 | + | |
| 129 | 151 | mLocClient.setLocOption(option); |
| 130 | 152 | mLocClient.start(); |
| 131 | 153 | //地图加载完毕监听 |
| ... | ... | @@ -142,7 +164,11 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 142 | 164 | new Handler().postDelayed(new Runnable() { |
| 143 | 165 | @Override |
| 144 | 166 | public void run() { |
| 145 | - MyMapUtil.drawMapLine(getContext(), baiduMap, trackPoints, R.color.green_50); | |
| 167 | + //绘制赛道轨迹 | |
| 168 | + if (getContext() == null) { | |
| 169 | + return; | |
| 170 | + } | |
| 171 | + MyMapUtil.drawServerLineTrack(getContext(), baiduMap, trackPoints, SortType.asc, R.color.green_50, R.drawable.icon_start, R.drawable.icon_end); | |
| 146 | 172 | } |
| 147 | 173 | }, 1500); |
| 148 | 174 | } |
| ... | ... | @@ -197,6 +223,20 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 197 | 223 | * 定位SDK监听函数 |
| 198 | 224 | */ |
| 199 | 225 | public class MyLocationListenner extends BDAbstractLocationListener { |
| 226 | + @Override | |
| 227 | + public void onLocDiagnosticMessage(int i, int i1, String s) { | |
| 228 | + super.onLocDiagnosticMessage(i, i1, s); | |
| 229 | + if (getContext() == null) { | |
| 230 | + return; | |
| 231 | + } | |
| 232 | + if (i == 67) { | |
| 233 | + Toast.makeText(getContext(), getContext().getString(R.string.loc_check_internet), Toast.LENGTH_SHORT).show(); | |
| 234 | + } else if (i == 161 && i1 == 1) { | |
| 235 | + Toast.makeText(getContext(), getContext().getString(R.string.loc_open_gps), Toast.LENGTH_SHORT).show(); | |
| 236 | + } else if (i == 161 && i1 == 2) { | |
| 237 | + Toast.makeText(getContext(), getContext().getString(R.string.loc_open_wifi), Toast.LENGTH_SHORT).show(); | |
| 238 | + } | |
| 239 | + } | |
| 200 | 240 | |
| 201 | 241 | @Override |
| 202 | 242 | public void onReceiveLocation(BDLocation location) { |
| ... | ... | @@ -228,31 +268,38 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 228 | 268 | return; |
| 229 | 269 | } |
| 230 | 270 | MapStatus.Builder builder = new MapStatus.Builder(); |
| 271 | + //不是第一次定位 | |
| 272 | + if (!isFirstLoc) { | |
| 273 | + if (currentPoints.size() > 0) { | |
| 274 | + //进行判断 | |
| 275 | + LatLng lastLatLng = currentPoints.get(currentPoints.size() - 1); | |
| 276 | + LatLng curLatLng = new LatLng(location.getLatitude(), | |
| 277 | + location.getLongitude()); | |
| 278 | + Log.e(TAG, "onReceiveLocation: 距离:" + DistanceUtil.getDistance(lastLatLng, curLatLng)); | |
| 279 | + if (DistanceUtil.getDistance(lastLatLng, curLatLng) > 1) { | |
| 280 | + currentPoints.add(curLatLng); | |
| 281 | + } | |
| 282 | + } else { | |
| 283 | + currentPoints.add(new LatLng(location.getLatitude(), | |
| 284 | + location.getLongitude())); | |
| 285 | + } | |
| 231 | 286 | |
| 232 | -// if (isFirstLoc) { | |
| 233 | -// isFirstLoc = false; | |
| 234 | - firstLatLng = new LatLng(location.getLatitude(), | |
| 287 | + //判断当前集合列表是否可以划线(至少两个点) | |
| 288 | + if (currentPoints != null && currentPoints.size() > 1) { | |
| 289 | + //判断当前是否已经在地图上画点 | |
| 290 | + if (currentLine != null) { | |
| 291 | + currentLine.remove(); | |
| 292 | + } | |
| 293 | + //开始划线 | |
| 294 | + if (getContext() == null) { | |
| 295 | + return; | |
| 296 | + } | |
| 297 | + currentLine = MyMapUtil.drawMapLine(getContext(), baiduMap, currentPoints, R.color.red); | |
| 298 | + } | |
| 299 | + } | |
| 300 | + myCurLatLng = new LatLng(location.getLatitude(), | |
| 235 | 301 | location.getLongitude()); |
| 236 | 302 | baiduMap.setMyLocationData(mylocation); |
| 237 | -// if (trackPoints!=null){ | |
| 238 | -// Log.e(TAG, "trackPoints: "+MyMapUtil.isInPolygon(firstLatLng,trackPoints) ); | |
| 239 | -// } | |
| 240 | -// if (isFirstLoc) { | |
| 241 | -// builder.target(firstLatLng).zoom(DEFULT_ZOOM); | |
| 242 | -// isFirstLoc = false; | |
| 243 | -// } else { | |
| 244 | -// float current = baiduMap.getMapStatus().zoom; | |
| 245 | -// builder.target(firstLatLng).zoom(current); | |
| 246 | -// | |
| 247 | -// } | |
| 248 | -// baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); | |
| 249 | -// //显示当前位置图标 | |
| 250 | -// Bitmap pointBitmap = BitmapUtil.getBitmapFromDp(getContext(), BitmapFactory.decodeResource(getContext().getResources(), R.drawable.rt_ic_location), 40, 40); | |
| 251 | -// currentMark = new MarkerOptions().position(firstLatLng).icon(BitmapDescriptorFactory.fromBitmap(pointBitmap)); | |
| 252 | -// baiduMap.addOverlay(currentMark); | |
| 253 | - | |
| 254 | - | |
| 255 | -// } | |
| 256 | 303 | } |
| 257 | 304 | } |
| 258 | 305 | |
| ... | ... | @@ -342,6 +389,7 @@ public class RunningMapFragmentView implements MvpView, SensorEventListener { |
| 342 | 389 | |
| 343 | 390 | } |
| 344 | 391 | |
| 392 | + | |
| 345 | 393 | public void onResume() { |
| 346 | 394 | if (mMapView != null) { |
| 347 | 395 | mMapView.onResume(); | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/model/Constant.java
| ... | ... | @@ -6,5 +6,7 @@ public class Constant { |
| 6 | 6 | public static final int SERVICE_STEP_COUNT_CONTINUE = 2;//继续计步 |
| 7 | 7 | public static final int SERVICE_STEP_COUNT_RESET_SPEED = 3;//重置速度 |
| 8 | 8 | public static final int FRAGMENT_RUN_CHRONOMETER = 4;//同步计时器 |
| 9 | + public static final int EXIT_RANGE = 5;//超出范围 | |
| 10 | + public static final int ENTER_RANGE = 6;//进入范围 | |
| 9 | 11 | |
| 10 | 12 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/model/RoutePoint.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.model; | |
| 2 | + | |
| 3 | +public class RoutePoint { | |
| 4 | + private double lat; | |
| 5 | + private double lng; | |
| 6 | + | |
| 7 | + public RoutePoint() { | |
| 8 | + } | |
| 9 | + | |
| 10 | + public RoutePoint(double lat, double lng) { | |
| 11 | + this.lat = lat; | |
| 12 | + this.lng = lng; | |
| 13 | + } | |
| 14 | + | |
| 15 | + public double getLat() { | |
| 16 | + return lat; | |
| 17 | + } | |
| 18 | + | |
| 19 | + public void setLat(double lat) { | |
| 20 | + this.lat = lat; | |
| 21 | + } | |
| 22 | + | |
| 23 | + public double getLng() { | |
| 24 | + return lng; | |
| 25 | + } | |
| 26 | + | |
| 27 | + public void setLng(double lng) { | |
| 28 | + this.lng = lng; | |
| 29 | + } | |
| 30 | +} | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/service/StepService.java
| ... | ... | @@ -147,9 +147,8 @@ public class StepService extends Service implements SensorEventListener { |
| 147 | 147 | //打包周期 |
| 148 | 148 | private int packInterval = 10; |
| 149 | 149 | // 轨迹服务ID |
| 150 | -// public static final long serviceId = 213511; | |
| 151 | -//杨帅 | |
| 152 | - public static final long serviceId = 213553; | |
| 150 | + public static final long serviceId = 213511;//杨帅 | |
| 151 | +// public static final long serviceId = 213553; | |
| 153 | 152 | |
| 154 | 153 | // 设备标识 |
| 155 | 154 | public static String entityName = ""; |
| ... | ... | @@ -170,7 +169,6 @@ public class StepService extends Service implements SensorEventListener { |
| 170 | 169 | |
| 171 | 170 | @Override |
| 172 | 171 | public void onCreate() { |
| 173 | - Log.e("执行onCreate", "onCreate"); | |
| 174 | 172 | super.onCreate(); |
| 175 | 173 | init(); |
| 176 | 174 | showStartForegroundNotification(); |
| ... | ... | @@ -325,11 +323,11 @@ public class StepService extends Service implements SensorEventListener { |
| 325 | 323 | } |
| 326 | 324 | //超出范围 |
| 327 | 325 | if (alarmPushInfo.getMonitoredAction() == MonitoredAction.exit) { |
| 328 | - | |
| 326 | + EventBus.getDefault().post(new MessageEvent(Constant.EXIT_RANGE, "")); | |
| 329 | 327 | } |
| 330 | 328 | //进入范围 |
| 331 | 329 | else if (alarmPushInfo.getMonitoredAction() == MonitoredAction.enter) { |
| 332 | - | |
| 330 | + EventBus.getDefault().post(new MessageEvent(Constant.ENTER_RANGE, "")); | |
| 333 | 331 | } |
| 334 | 332 | Toast.makeText(getApplicationContext(), "onPushCallback:" + alarmPushInfo.getMonitoredAction(), Toast.LENGTH_SHORT).show(); |
| 335 | 333 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/activity/PedometerMainActivity.java
| ... | ... | @@ -13,6 +13,7 @@ import android.support.annotation.NonNull; |
| 13 | 13 | import android.support.v4.app.NotificationManagerCompat; |
| 14 | 14 | import android.support.v4.content.ContextCompat; |
| 15 | 15 | import android.util.Log; |
| 16 | +import android.view.KeyEvent; | |
| 16 | 17 | import android.widget.Toast; |
| 17 | 18 | |
| 18 | 19 | import com.alibaba.android.arouter.facade.annotation.Route; |
| ... | ... | @@ -40,6 +41,7 @@ public class PedometerMainActivity extends QMUIFragmentActivity { |
| 40 | 41 | private NotificationManagerCompat notificationManagerCompat; |
| 41 | 42 | private boolean isOpen; |
| 42 | 43 | private PermissionsUtils mPermissionsUtils = new PermissionsUtils();//权限申请 |
| 44 | + private RunMainFragment fragment; | |
| 43 | 45 | |
| 44 | 46 | @Override |
| 45 | 47 | protected int getContextViewId() { |
| ... | ... | @@ -149,7 +151,7 @@ public class PedometerMainActivity extends QMUIFragmentActivity { |
| 149 | 151 | } |
| 150 | 152 | |
| 151 | 153 | private void addFragment() { |
| 152 | - QMUIFragment fragment = new RunMainFragment(); | |
| 154 | + fragment = new RunMainFragment(); | |
| 153 | 155 | getSupportFragmentManager().beginTransaction() |
| 154 | 156 | .add(getContextViewId(), fragment, fragment.getClass().getSimpleName()) |
| 155 | 157 | .addToBackStack(fragment.getClass().getSimpleName()) |
| ... | ... | @@ -236,4 +238,10 @@ public class PedometerMainActivity extends QMUIFragmentActivity { |
| 236 | 238 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
| 237 | 239 | mPermissionsUtils.dealResult(requestCode, permissions, grantResults); |
| 238 | 240 | } |
| 241 | + | |
| 242 | + | |
| 243 | + @Override | |
| 244 | + public void onBackPressed() { | |
| 245 | + return; | |
| 246 | + } | |
| 239 | 247 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/activity/RunLineActivity.java
| ... | ... | @@ -23,6 +23,7 @@ public class RunLineActivity extends AppCompatActivity { |
| 23 | 23 | setContentView(R.layout.activity_run_line); |
| 24 | 24 | |
| 25 | 25 | getSupportFragmentManager().beginTransaction().replace(R.id.run_line_container, new RunLineFragment()).commit(); |
| 26 | +// getSupportFragmentManager().beginTransaction().replace(R.id.run_line_container, new RunningFinishFragment()).commit(); | |
| 26 | 27 | |
| 27 | 28 | } |
| 28 | 29 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/activity/RunRaceDetailActivity.java
| ... | ... | @@ -16,9 +16,12 @@ import com.cnlive.libs.base.ui.QMUIFragment; |
| 16 | 16 | import com.cnlive.libs.base.ui.QMUIFragmentActivity; |
| 17 | 17 | import com.cnlive.libs.base.util.StatusBarUtil2; |
| 18 | 18 | import com.cnlive.moudle.pedometer.model.RunningMapBean; |
| 19 | +import com.cnlive.moudle.pedometer.sql.entity.UserStepEntity; | |
| 20 | +import com.cnlive.moudle.pedometer.ui.fragment.RunMainFragment; | |
| 19 | 21 | import com.cnlive.moudle.pedometer.ui.fragment.RunRaceDetailFragment; |
| 20 | 22 | import com.cnlive.moudle.pedometer.ui.fragment.RunningMapFragment; |
| 21 | 23 | import com.cnlive.moudle.pedometer.ui.widget.FivePersonIconView; |
| 24 | +import com.cnlive.moudle.pedometer.utils.StepUtil; | |
| 22 | 25 | import com.example.moudle_pedometer.R; |
| 23 | 26 | |
| 24 | 27 | import java.util.ArrayList; |
| ... | ... | @@ -41,12 +44,20 @@ public class RunRaceDetailActivity extends QMUIFragmentActivity { |
| 41 | 44 | protected void onCreate(Bundle savedInstanceState) { |
| 42 | 45 | super.onCreate(savedInstanceState); |
| 43 | 46 | StatusBarUtil2.setColor(this, getResources().getColor(R.color.run_main_bg), 0); |
| 44 | - addFragment(); | |
| 45 | - | |
| 47 | + //判断用户是否结束运动 | |
| 48 | + String uid = "yangshuai"; | |
| 49 | + UserStepEntity userStepEntity = StepUtil.getUserStepData(getApplicationContext(), uid); | |
| 50 | + //没有在数据库中找到相关记录 | |
| 51 | + if (userStepEntity == null) { | |
| 52 | + addFragment(new RunRaceDetailFragment()); | |
| 53 | + } | |
| 54 | + //找到记录 | |
| 55 | + else { | |
| 56 | + addFragment(new RunMainFragment()); | |
| 57 | + } | |
| 46 | 58 | } |
| 47 | 59 | |
| 48 | - private void addFragment() { | |
| 49 | - QMUIFragment fragment = new RunRaceDetailFragment(); | |
| 60 | + private void addFragment(QMUIFragment fragment) { | |
| 50 | 61 | getSupportFragmentManager().beginTransaction() |
| 51 | 62 | .add(getContextViewId(), fragment, fragment.getClass().getSimpleName()) |
| 52 | 63 | .addToBackStack(fragment.getClass().getSimpleName()) |
| ... | ... | @@ -56,7 +67,7 @@ public class RunRaceDetailActivity extends QMUIFragmentActivity { |
| 56 | 67 | @Override |
| 57 | 68 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
| 58 | 69 | super.onActivityResult(requestCode, resultCode, data); |
| 59 | - if(resultCode == 1002){ | |
| 70 | + if (resultCode == 1002) { | |
| 60 | 71 | |
| 61 | 72 | } |
| 62 | 73 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/fragment/RunMainFragment.java
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/fragment/RunRaceDetailFragment.java
| ... | ... | @@ -15,8 +15,11 @@ import android.widget.LinearLayout; |
| 15 | 15 | import com.cnlive.libs.base.ui.QMUIFragment; |
| 16 | 16 | import com.cnlive.moudle.pedometer.frame.presenter.RunRaceDetailFragmentPresenter; |
| 17 | 17 | import com.cnlive.moudle.pedometer.frame.view.RunRaceDetailFragmentView; |
| 18 | +import com.cnlive.moudle.pedometer.sql.entity.UserStepEntity; | |
| 18 | 19 | import com.cnlive.moudle.pedometer.ui.widget.FivePersonIconView; |
| 20 | +import com.cnlive.moudle.pedometer.utils.ChineseToSpeechUtil; | |
| 19 | 21 | import com.cnlive.moudle.pedometer.utils.ScreenUtil; |
| 22 | +import com.cnlive.moudle.pedometer.utils.StepUtil; | |
| 20 | 23 | import com.example.moudle_pedometer.R; |
| 21 | 24 | import com.example.moudle_pedometer.databinding.FragmentRunRaceDetailBinding; |
| 22 | 25 | import com.sothree.slidinguppanel.SlidingUpPanelLayout; |
| ... | ... | @@ -36,6 +39,7 @@ import static android.content.Context.SENSOR_SERVICE; |
| 36 | 39 | public class RunRaceDetailFragment extends QMUIFragment<RunRaceDetailFragmentView, RunRaceDetailFragmentPresenter, FragmentRunRaceDetailBinding> { |
| 37 | 40 | private static final String TAG = "RunRaceDetailFragment"; |
| 38 | 41 | private SensorManager mSensorManager; |
| 42 | + | |
| 39 | 43 | @Override |
| 40 | 44 | protected int getToolbarId() { |
| 41 | 45 | return 0; |
| ... | ... | @@ -54,12 +58,14 @@ public class RunRaceDetailFragment extends QMUIFragment<RunRaceDetailFragmentVie |
| 54 | 58 | @Override |
| 55 | 59 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 56 | 60 | super.onViewCreated(view, savedInstanceState); |
| 57 | - mSensorManager = (SensorManager) getActivity().getSystemService(SENSOR_SERVICE);//获取传感器管理服务 | |
| 58 | 61 | |
| 62 | + mSensorManager = (SensorManager) getActivity().getSystemService(SENSOR_SERVICE);//获取传感器管理服务 | |
| 59 | 63 | if (getMvpView() != null) { |
| 60 | 64 | getMvpView().initView(); |
| 61 | 65 | } |
| 66 | + | |
| 62 | 67 | } |
| 68 | + | |
| 63 | 69 | @Override |
| 64 | 70 | public void onResume() { |
| 65 | 71 | super.onResume(); |
| ... | ... | @@ -96,6 +102,7 @@ public class RunRaceDetailFragment extends QMUIFragment<RunRaceDetailFragmentVie |
| 96 | 102 | if (getMvpView() != null) { |
| 97 | 103 | getMvpView().onDestroy(); |
| 98 | 104 | } |
| 105 | + | |
| 99 | 106 | } |
| 100 | 107 | // private void test() { |
| 101 | 108 | // BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(getActivity()); | ... | ... |
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.app.Service; | |
| 3 | 4 | import android.content.Context; |
| 4 | 5 | import android.hardware.Sensor; |
| 5 | 6 | import android.hardware.SensorManager; |
| 6 | 7 | import android.os.Bundle; |
| 7 | 8 | import android.os.Handler; |
| 8 | 9 | import android.os.SystemClock; |
| 10 | +import android.os.Vibrator; | |
| 9 | 11 | import android.support.annotation.Nullable; |
| 10 | 12 | import android.text.TextUtils; |
| 11 | 13 | import android.util.Log; |
| ... | ... | @@ -20,6 +22,8 @@ import com.cnlive.moudle.pedometer.model.RunningMapBean; |
| 20 | 22 | import com.cnlive.moudle.pedometer.model.Constant; |
| 21 | 23 | import com.cnlive.moudle.pedometer.model.MessageEvent; |
| 22 | 24 | import com.cnlive.moudle.pedometer.service.StepService; |
| 25 | +import com.cnlive.moudle.pedometer.ui.widget.TipDialog; | |
| 26 | +import com.cnlive.moudle.pedometer.utils.ChineseToSpeechUtil; | |
| 23 | 27 | import com.cnlive.moudle.pedometer.utils.GsonUtil; |
| 24 | 28 | import com.cnlive.moudle.pedometer.utils.MyMapUtil; |
| 25 | 29 | import com.cnlive.moudle.pedometer.utils.MySpHelper; |
| ... | ... | @@ -46,6 +50,9 @@ public class RunningMapFragment extends QMUIFragment<RunningMapFragmentView, Run |
| 46 | 50 | private RunningMapBean runningMapBean; |
| 47 | 51 | private SensorManager mSensorManager; |
| 48 | 52 | private String test = "[{\"latitude\":39.933889208848,\"latitudeE6\":3.9933889208848E7,\"longitude\":116.30900265517,\"longitudeE6\":1.1630900265517001E8},{\"latitude\":39.933868507347,\"latitudeE6\":3.9933868507347E7,\"longitude\":116.30865416508,\"longitudeE6\":1.1630865416508E8},{\"latitude\":39.934756505077,\"latitudeE6\":3.9934756505077E7,\"longitude\":116.30860516469,\"longitudeE6\":1.1630860516468999E8},{\"latitude\":39.934781620502,\"latitudeE6\":3.9934781620502E7,\"longitude\":116.30961013007,\"longitudeE6\":1.1630961013007E8},{\"latitude\":39.934881620374,\"latitudeE6\":3.9934881620374E7,\"longitude\":116.30960513008,\"longitudeE6\":1.1630960513008E8},{\"latitude\":39.934077623132,\"latitudeE6\":3.9934077623132E7,\"longitude\":116.30965812942,\"longitudeE6\":1.1630965812942E8},{\"latitude\":39.933972618463,\"latitudeE6\":3.9933972618463E7,\"longitude\":116.30962113087,\"longitudeE6\":1.1630962113087E8},{\"latitude\":39.933932608856,\"latitudeE6\":3.9933932608856E7,\"longitude\":116.30953913383,\"longitudeE6\":1.1630953913383E8},{\"latitude\":39.933903844942,\"latitudeE6\":3.9933903844942E7,\"longitude\":116.30918357649,\"longitudeE6\":1.1630918357649E8}]"; |
| 53 | + //创建震动服务对象 | |
| 54 | + private Vibrator mVibrator; | |
| 55 | + private TipDialog tipDialog; | |
| 49 | 56 | |
| 50 | 57 | @Override |
| 51 | 58 | protected int getToolbarId() { |
| ... | ... | @@ -82,7 +89,12 @@ public class RunningMapFragment extends QMUIFragment<RunningMapFragmentView, Run |
| 82 | 89 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 83 | 90 | super.onViewCreated(view, savedInstanceState); |
| 84 | 91 | EventBus.getDefault().register(this); |
| 85 | - mSensorManager = (SensorManager) getActivity().getSystemService(SENSOR_SERVICE);//获取传感器管理服务 | |
| 92 | + //获取传感器管理服务 | |
| 93 | + mSensorManager = (SensorManager) getActivity().getSystemService(SENSOR_SERVICE); | |
| 94 | + //获取手机震动服务 | |
| 95 | + mVibrator = (Vibrator) getActivity().getSystemService(Service.VIBRATOR_SERVICE); | |
| 96 | + //初始化提示框 | |
| 97 | + initTipDialog(); | |
| 86 | 98 | List<LatLng> trackPoints = GsonUtil.jsonToList(test, LatLng.class); |
| 87 | 99 | if (getArguments() != null) { |
| 88 | 100 | runningMapBean = (RunningMapBean) getArguments().getSerializable("runningMapBean"); |
| ... | ... | @@ -113,6 +125,7 @@ public class RunningMapFragment extends QMUIFragment<RunningMapFragmentView, Run |
| 113 | 125 | getPresenter().queryHistoryTrace(getActivity(), StepService.entityName, startTime, endTime); |
| 114 | 126 | //查询实时轨迹 |
| 115 | 127 | getPresenter().queryRealTimeTrace(getActivity(), StepService.entityName, startTime); |
| 128 | + | |
| 116 | 129 | } |
| 117 | 130 | |
| 118 | 131 | |
| ... | ... | @@ -144,6 +157,8 @@ public class RunningMapFragment extends QMUIFragment<RunningMapFragmentView, Run |
| 144 | 157 | //取消注册传感器监听 |
| 145 | 158 | mSensorManager.unregisterListener(getMvpView()); |
| 146 | 159 | } |
| 160 | + ChineseToSpeechUtil.destroy(); | |
| 161 | + | |
| 147 | 162 | } |
| 148 | 163 | |
| 149 | 164 | @Override |
| ... | ... | @@ -152,6 +167,7 @@ public class RunningMapFragment extends QMUIFragment<RunningMapFragmentView, Run |
| 152 | 167 | if (getMvpView() != null) { |
| 153 | 168 | getMvpView().onPause(); |
| 154 | 169 | } |
| 170 | + | |
| 155 | 171 | } |
| 156 | 172 | |
| 157 | 173 | @Override |
| ... | ... | @@ -179,5 +195,32 @@ public class RunningMapFragment extends QMUIFragment<RunningMapFragmentView, Run |
| 179 | 195 | getMvpView().resetSpeed(); |
| 180 | 196 | } |
| 181 | 197 | } |
| 198 | + //超出范围 | |
| 199 | + else if (messageEvent.getMessageType() == Constant.EXIT_RANGE) { | |
| 200 | + ChineseToSpeechUtil.speech(getActivity().getApplicationContext(), "您已偏离预定轨迹!"); | |
| 201 | + if (mVibrator != null) { | |
| 202 | + //设置震动周期,数组表示时间:等待+执行,单位是毫秒,下面操作代表:等待100,执行100,等待100,执行1000, | |
| 203 | + //后面的数字如果为-1代表不重复,之执行一次,其他代表会重复,0代表从数组的第0个位置开始 | |
| 204 | + mVibrator.vibrate(new long[]{100, 1000, 100, 1000}, -1); | |
| 205 | + } | |
| 206 | + if (tipDialog != null) { | |
| 207 | + tipDialog.show(); | |
| 208 | + } | |
| 209 | + } | |
| 182 | 210 | } |
| 211 | + | |
| 212 | + private void initTipDialog() { | |
| 213 | + if (tipDialog == null) { | |
| 214 | + tipDialog = new TipDialog(getActivity(), "您已偏离预定轨迹!", "我知道了", R.color.green_round, new TipDialog.DialogInterface() { | |
| 215 | + @Override | |
| 216 | + public void onClick(TipDialog dialog) { | |
| 217 | + dialog.dismiss(); | |
| 218 | + } | |
| 219 | + }); | |
| 220 | + tipDialog.setCancelable(false); | |
| 221 | + tipDialog.setCanceledOnTouchOutside(false); | |
| 222 | + } | |
| 223 | + } | |
| 224 | + | |
| 225 | + | |
| 183 | 226 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/ButtonAnimUtil.java
| ... | ... | @@ -21,106 +21,132 @@ public class ButtonAnimUtil { |
| 21 | 21 | |
| 22 | 22 | //设置控件放大动画 |
| 23 | 23 | public static void setViewZoomIn(View view) { |
| 24 | - AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画 | |
| 25 | - ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1, 1.2f); | |
| 26 | - ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1, 1.2f); | |
| 27 | - animatorSetsuofang.setDuration(DEFAULT_ZOOM_DURATION); | |
| 28 | - animatorSetsuofang.setInterpolator(new DecelerateInterpolator()); | |
| 29 | - animatorSetsuofang.play(scaleX).with(scaleY);//两个动画同时开始 | |
| 30 | - animatorSetsuofang.start(); | |
| 24 | + try { | |
| 25 | + AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画 | |
| 26 | + ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1, 1.2f); | |
| 27 | + ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1, 1.2f); | |
| 28 | + animatorSetsuofang.setDuration(DEFAULT_ZOOM_DURATION); | |
| 29 | + animatorSetsuofang.setInterpolator(new DecelerateInterpolator()); | |
| 30 | + animatorSetsuofang.play(scaleX).with(scaleY);//两个动画同时开始 | |
| 31 | + animatorSetsuofang.start(); | |
| 32 | + } catch (Exception e) { | |
| 33 | + } | |
| 31 | 34 | } |
| 32 | 35 | |
| 33 | 36 | //设置控件缩小动画 |
| 34 | 37 | public static void setViewZoomOut(View view) { |
| 35 | - AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画 | |
| 36 | - ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1.2f, 1); | |
| 37 | - ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1.2f, 1); | |
| 38 | - animatorSetsuofang.setDuration(DEFAULT_ZOOM_DURATION); | |
| 39 | - animatorSetsuofang.setInterpolator(new DecelerateInterpolator()); | |
| 40 | - animatorSetsuofang.play(scaleX).with(scaleY);//两个动画同时开始 | |
| 41 | - animatorSetsuofang.start(); | |
| 38 | + try { | |
| 39 | + AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画 | |
| 40 | + ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1.2f, 1); | |
| 41 | + ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1.2f, 1); | |
| 42 | + animatorSetsuofang.setDuration(DEFAULT_ZOOM_DURATION); | |
| 43 | + animatorSetsuofang.setInterpolator(new DecelerateInterpolator()); | |
| 44 | + animatorSetsuofang.play(scaleX).with(scaleY);//两个动画同时开始 | |
| 45 | + animatorSetsuofang.start(); | |
| 46 | + } catch (Exception e) { | |
| 47 | + } | |
| 42 | 48 | } |
| 43 | 49 | |
| 44 | 50 | //设置控件缩小动画 |
| 45 | 51 | public static void setViewDefault(View view) { |
| 46 | - AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画 | |
| 47 | - ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 1); | |
| 48 | - ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 1); | |
| 49 | - animatorSetsuofang.setDuration(DEFAULT_ZOOM_DURATION); | |
| 50 | - animatorSetsuofang.setInterpolator(new DecelerateInterpolator()); | |
| 51 | - animatorSetsuofang.play(scaleX).with(scaleY);//两个动画同时开始 | |
| 52 | - animatorSetsuofang.start(); | |
| 52 | + try { | |
| 53 | + AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画 | |
| 54 | + ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 1); | |
| 55 | + ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 1); | |
| 56 | + animatorSetsuofang.setDuration(DEFAULT_ZOOM_DURATION); | |
| 57 | + animatorSetsuofang.setInterpolator(new DecelerateInterpolator()); | |
| 58 | + animatorSetsuofang.play(scaleX).with(scaleY);//两个动画同时开始 | |
| 59 | + animatorSetsuofang.start(); | |
| 60 | + } catch (Exception e) { | |
| 61 | + } | |
| 53 | 62 | } |
| 54 | 63 | |
| 55 | 64 | //设置控件显示放大动画 |
| 56 | 65 | public static void setViewShowZoomIn(View view) { |
| 57 | - AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画 | |
| 58 | - ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 0, 1.2f); | |
| 59 | - ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 0, 1.2f); | |
| 60 | - animatorSetsuofang.setDuration(SHOW_VIEW_ZOOM_DURATION); | |
| 61 | - animatorSetsuofang.setInterpolator(new DecelerateInterpolator()); | |
| 62 | - animatorSetsuofang.play(scaleX).with(scaleY);//两个动画同时开始 | |
| 63 | - animatorSetsuofang.start(); | |
| 64 | - new Handler().postDelayed(new Runnable() { | |
| 65 | - @Override | |
| 66 | - public void run() { | |
| 67 | - AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画 | |
| 68 | - ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1.2f, 1); | |
| 69 | - ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1.2f, 1); | |
| 70 | - animatorSetsuofang.setDuration(SHOW_VIEW_ZOOM_DURATION); | |
| 71 | - animatorSetsuofang.setInterpolator(new DecelerateInterpolator()); | |
| 72 | - animatorSetsuofang.play(scaleX).with(scaleY);//两个动画同时开始 | |
| 73 | - animatorSetsuofang.start(); | |
| 74 | - } | |
| 75 | - }, SHOW_VIEW_ZOOM_DURATION); | |
| 66 | + try { | |
| 67 | + AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画 | |
| 68 | + ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 0, 1.2f); | |
| 69 | + ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 0, 1.2f); | |
| 70 | + animatorSetsuofang.setDuration(SHOW_VIEW_ZOOM_DURATION); | |
| 71 | + animatorSetsuofang.setInterpolator(new DecelerateInterpolator()); | |
| 72 | + animatorSetsuofang.play(scaleX).with(scaleY);//两个动画同时开始 | |
| 73 | + animatorSetsuofang.start(); | |
| 74 | + new Handler().postDelayed(new Runnable() { | |
| 75 | + @Override | |
| 76 | + public void run() { | |
| 77 | + if (view == null) { | |
| 78 | + return; | |
| 79 | + } | |
| 80 | + AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画 | |
| 81 | + ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1.2f, 1); | |
| 82 | + ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1.2f, 1); | |
| 83 | + animatorSetsuofang.setDuration(SHOW_VIEW_ZOOM_DURATION); | |
| 84 | + animatorSetsuofang.setInterpolator(new DecelerateInterpolator()); | |
| 85 | + animatorSetsuofang.play(scaleX).with(scaleY);//两个动画同时开始 | |
| 86 | + animatorSetsuofang.start(); | |
| 87 | + } | |
| 88 | + }, SHOW_VIEW_ZOOM_DURATION); | |
| 89 | + } catch (Exception e) { | |
| 90 | + } | |
| 76 | 91 | } |
| 77 | 92 | |
| 78 | 93 | //设置控件隐藏缩小动画 |
| 79 | 94 | public static void setViewHideZoomOut(View view) { |
| 80 | - AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画 | |
| 81 | - ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1, 0); | |
| 82 | - ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1, 0); | |
| 83 | - animatorSetsuofang.setDuration(HIDE_VIEW_ZOOM_DURATION); | |
| 84 | - animatorSetsuofang.setInterpolator(new DecelerateInterpolator()); | |
| 85 | - animatorSetsuofang.play(scaleX).with(scaleY);//两个动画同时开始 | |
| 86 | - animatorSetsuofang.start(); | |
| 95 | + try { | |
| 96 | + AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画 | |
| 97 | + ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1, 0); | |
| 98 | + ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1, 0); | |
| 99 | + animatorSetsuofang.setDuration(HIDE_VIEW_ZOOM_DURATION); | |
| 100 | + animatorSetsuofang.setInterpolator(new DecelerateInterpolator()); | |
| 101 | + animatorSetsuofang.play(scaleX).with(scaleY);//两个动画同时开始 | |
| 102 | + animatorSetsuofang.start(); | |
| 103 | + } catch (Exception e) { | |
| 104 | + } | |
| 87 | 105 | } |
| 88 | 106 | |
| 89 | 107 | //设置时间显示放大动画 |
| 90 | 108 | public static void setTimeShowZoomIn(View view) { |
| 91 | - ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 0, 1.4f); | |
| 92 | - ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 0, 1.4f); | |
| 93 | - ObjectAnimator scaleX1 = ObjectAnimator.ofFloat(view, "scaleX", 1.4f, 1); | |
| 94 | - ObjectAnimator scaleY1 = ObjectAnimator.ofFloat(view, "scaleY", 1.4f, 1); | |
| 95 | - ObjectAnimator scaleX2 = ObjectAnimator.ofFloat(view, "scaleX", 1, 0); | |
| 96 | - ObjectAnimator scaleY2 = ObjectAnimator.ofFloat(view, "scaleY", 1, 0); | |
| 97 | - AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画 | |
| 98 | - animatorSetsuofang.setDuration(100); | |
| 99 | - animatorSetsuofang.setInterpolator(new DecelerateInterpolator()); | |
| 100 | - animatorSetsuofang.play(scaleX).with(scaleY); | |
| 101 | - animatorSetsuofang.start(); | |
| 102 | - new Handler().postDelayed(new Runnable() { | |
| 103 | - @Override | |
| 104 | - public void run() { | |
| 105 | - AnimatorSet animatorSetsuofang2 = new AnimatorSet();//组合动画 | |
| 106 | - animatorSetsuofang2.setDuration(100); | |
| 107 | - animatorSetsuofang2.setInterpolator(new DecelerateInterpolator()); | |
| 108 | - animatorSetsuofang2.play(scaleX1).with(scaleY1); | |
| 109 | - animatorSetsuofang2.start(); | |
| 110 | - } | |
| 111 | - }, 100); | |
| 112 | - | |
| 113 | - new Handler().postDelayed(new Runnable() { | |
| 114 | - @Override | |
| 115 | - public void run() { | |
| 116 | - AnimatorSet animatorSetsuofang3 = new AnimatorSet();//组合动画 | |
| 117 | - animatorSetsuofang3.setDuration(10); | |
| 118 | - animatorSetsuofang3.setInterpolator(new DecelerateInterpolator()); | |
| 119 | - animatorSetsuofang3.play(scaleX2).with(scaleY2); | |
| 120 | - animatorSetsuofang3.start(); | |
| 121 | - } | |
| 122 | - }, 300); | |
| 109 | + try { | |
| 110 | + ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 0, 1.4f); | |
| 111 | + ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 0, 1.4f); | |
| 112 | + ObjectAnimator scaleX1 = ObjectAnimator.ofFloat(view, "scaleX", 1.4f, 1); | |
| 113 | + ObjectAnimator scaleY1 = ObjectAnimator.ofFloat(view, "scaleY", 1.4f, 1); | |
| 114 | + ObjectAnimator scaleX2 = ObjectAnimator.ofFloat(view, "scaleX", 1, 0); | |
| 115 | + ObjectAnimator scaleY2 = ObjectAnimator.ofFloat(view, "scaleY", 1, 0); | |
| 116 | + AnimatorSet animatorSetsuofang = new AnimatorSet();//组合动画 | |
| 117 | + animatorSetsuofang.setDuration(100); | |
| 118 | + animatorSetsuofang.setInterpolator(new DecelerateInterpolator()); | |
| 119 | + animatorSetsuofang.play(scaleX).with(scaleY); | |
| 120 | + animatorSetsuofang.start(); | |
| 121 | + new Handler().postDelayed(new Runnable() { | |
| 122 | + @Override | |
| 123 | + public void run() { | |
| 124 | + if (view == null) { | |
| 125 | + return; | |
| 126 | + } | |
| 127 | + AnimatorSet animatorSetsuofang2 = new AnimatorSet();//组合动画 | |
| 128 | + animatorSetsuofang2.setDuration(100); | |
| 129 | + animatorSetsuofang2.setInterpolator(new DecelerateInterpolator()); | |
| 130 | + animatorSetsuofang2.play(scaleX1).with(scaleY1); | |
| 131 | + animatorSetsuofang2.start(); | |
| 132 | + } | |
| 133 | + }, 100); | |
| 123 | 134 | |
| 135 | + new Handler().postDelayed(new Runnable() { | |
| 136 | + @Override | |
| 137 | + public void run() { | |
| 138 | + if (view == null) { | |
| 139 | + return; | |
| 140 | + } | |
| 141 | + AnimatorSet animatorSetsuofang3 = new AnimatorSet();//组合动画 | |
| 142 | + animatorSetsuofang3.setDuration(10); | |
| 143 | + animatorSetsuofang3.setInterpolator(new DecelerateInterpolator()); | |
| 144 | + animatorSetsuofang3.play(scaleX2).with(scaleY2); | |
| 145 | + animatorSetsuofang3.start(); | |
| 146 | + } | |
| 147 | + }, 300); | |
| 148 | + } catch (Exception e) { | |
| 149 | + } | |
| 124 | 150 | } |
| 125 | 151 | |
| 126 | 152 | |
| ... | ... | @@ -131,46 +157,49 @@ public class ButtonAnimUtil { |
| 131 | 157 | * @param closeFlag |
| 132 | 158 | */ |
| 133 | 159 | public static void startAnimation(View view, boolean closeFlag) { |
| 134 | - //因为CircularReveal动画是api21之后才有的,所以加个判断语句,免得崩溃 | |
| 135 | - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
| 136 | - int cicular_R = view.getHeight() / 2 > view.getWidth() / 2 ? view.getHeight() / 2 : view.getWidth() / 2; | |
| 137 | - Animator animator = null; | |
| 138 | - if (!closeFlag) { | |
| 139 | - animator = ViewAnimationUtils.createCircularReveal(view, (int) view.getWidth() / 2, (int) view.getHeight() / 2, 0, cicular_R); | |
| 140 | - } else { | |
| 141 | - animator = ViewAnimationUtils.createCircularReveal(view, (int) view.getWidth() / 2, (int) view.getHeight() / 2, cicular_R, 0); | |
| 142 | - } | |
| 143 | - animator.addListener(new Animator.AnimatorListener() { | |
| 144 | - @Override | |
| 145 | - public void onAnimationStart(Animator animator) { | |
| 146 | - | |
| 160 | + try { | |
| 161 | + //因为CircularReveal动画是api21之后才有的,所以加个判断语句,免得崩溃 | |
| 162 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
| 163 | + int cicular_R = view.getHeight() / 2 > view.getWidth() / 2 ? view.getHeight() / 2 : view.getWidth() / 2; | |
| 164 | + Animator animator = null; | |
| 165 | + if (!closeFlag) { | |
| 166 | + animator = ViewAnimationUtils.createCircularReveal(view, (int) view.getWidth() / 2, (int) view.getHeight() / 2, 0, cicular_R); | |
| 167 | + } else { | |
| 168 | + animator = ViewAnimationUtils.createCircularReveal(view, (int) view.getWidth() / 2, (int) view.getHeight() / 2, cicular_R, 0); | |
| 147 | 169 | } |
| 170 | + animator.addListener(new Animator.AnimatorListener() { | |
| 171 | + @Override | |
| 172 | + public void onAnimationStart(Animator animator) { | |
| 148 | 173 | |
| 149 | - @Override | |
| 150 | - public void onAnimationEnd(Animator animator) { | |
| 151 | - if (closeFlag) { | |
| 152 | - view.setVisibility(View.GONE); | |
| 153 | 174 | } |
| 154 | - } | |
| 155 | 175 | |
| 156 | - @Override | |
| 157 | - public void onAnimationCancel(Animator animator) { | |
| 176 | + @Override | |
| 177 | + public void onAnimationEnd(Animator animator) { | |
| 178 | + if (closeFlag) { | |
| 179 | + view.setVisibility(View.GONE); | |
| 180 | + } | |
| 181 | + } | |
| 158 | 182 | |
| 159 | - } | |
| 183 | + @Override | |
| 184 | + public void onAnimationCancel(Animator animator) { | |
| 160 | 185 | |
| 161 | - @Override | |
| 162 | - public void onAnimationRepeat(Animator animator) { | |
| 186 | + } | |
| 187 | + | |
| 188 | + @Override | |
| 189 | + public void onAnimationRepeat(Animator animator) { | |
| 163 | 190 | |
| 191 | + } | |
| 192 | + }); | |
| 193 | + animator.setDuration(350); | |
| 194 | + animator.start(); | |
| 195 | + } else { | |
| 196 | + if (closeFlag) { | |
| 197 | + view.setVisibility(View.GONE); | |
| 164 | 198 | } |
| 165 | - }); | |
| 166 | - animator.setDuration(350); | |
| 167 | - animator.start(); | |
| 168 | - } else { | |
| 169 | - if (closeFlag) { | |
| 170 | - view.setVisibility(View.GONE); | |
| 171 | 199 | } |
| 172 | - } | |
| 173 | 200 | |
| 201 | + } catch (Exception e) { | |
| 202 | + } | |
| 174 | 203 | } |
| 175 | 204 | |
| 176 | 205 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/ChineseToSpeechUtil.java
0 → 100644
| 1 | +package com.cnlive.moudle.pedometer.utils; | |
| 2 | + | |
| 3 | +import android.app.Application; | |
| 4 | +import android.content.Context; | |
| 5 | +import android.speech.tts.TextToSpeech; | |
| 6 | + | |
| 7 | +import java.util.Locale; | |
| 8 | + | |
| 9 | +public class ChineseToSpeechUtil { | |
| 10 | + private static TextToSpeech textToSpeech; | |
| 11 | + | |
| 12 | + | |
| 13 | + public static void speech(Context context, String text) { | |
| 14 | + if (textToSpeech == null) { | |
| 15 | + textToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() { | |
| 16 | + @Override | |
| 17 | + public void onInit(int status) { | |
| 18 | + if (status == TextToSpeech.SUCCESS) { | |
| 19 | + int result = textToSpeech.setLanguage(Locale.CHINA); | |
| 20 | + if (result == TextToSpeech.LANG_MISSING_DATA | |
| 21 | + || result == TextToSpeech.LANG_NOT_SUPPORTED) { | |
| 22 | +// new CoolToast(Application.getContext()).show("不支持朗读功能"); | |
| 23 | + } else { | |
| 24 | + // 设置音调,值越大声音越尖(女生),值越小则变成男声,1.0是常规 | |
| 25 | + textToSpeech.setPitch(1.0f); | |
| 26 | + // 设置语速 | |
| 27 | + textToSpeech.setSpeechRate(1f); | |
| 28 | + textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null); | |
| 29 | + } | |
| 30 | + } | |
| 31 | + } | |
| 32 | + }); | |
| 33 | + }else { | |
| 34 | + textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null); | |
| 35 | + } | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + } | |
| 40 | + | |
| 41 | + public static void destroy() { | |
| 42 | + if (textToSpeech != null) { | |
| 43 | + textToSpeech.stop(); | |
| 44 | + textToSpeech.shutdown(); | |
| 45 | + textToSpeech=null; | |
| 46 | + } | |
| 47 | + } | |
| 48 | + | |
| 49 | +} | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/MyMapUtil.java
| ... | ... | @@ -13,7 +13,9 @@ import com.baidu.mapapi.map.PolylineOptions; |
| 13 | 13 | import com.baidu.mapapi.model.LatLng; |
| 14 | 14 | import com.baidu.mapapi.utils.DistanceUtil; |
| 15 | 15 | import com.baidu.trace.model.SortType; |
| 16 | +import com.cnlive.moudle.pedometer.model.RoutePoint; | |
| 16 | 17 | |
| 18 | +import java.util.ArrayList; | |
| 17 | 19 | import java.util.List; |
| 18 | 20 | |
| 19 | 21 | /** |
| ... | ... | @@ -35,16 +37,19 @@ public class MyMapUtil { |
| 35 | 37 | */ |
| 36 | 38 | public static Overlay drawHistoryTrack(Context context, BaiduMap baiduMap, List<LatLng> points, SortType sortType, int lineColor, int startIconRes, int endIconRes) { |
| 37 | 39 | // 绘制新覆盖物前,清空之前的覆盖物 |
| 38 | - baiduMap.clear(); | |
| 39 | 40 | if (points == null || points.size() == 0) { |
| 40 | 41 | return null; |
| 41 | 42 | } |
| 42 | 43 | //只有一个点 |
| 43 | 44 | if (points.size() == 1) { |
| 44 | - Bitmap pointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), startIconRes), 40, 40); | |
| 45 | - OverlayOptions startOptions = new MarkerOptions().position(points.get(0)).icon(BitmapDescriptorFactory.fromBitmap(pointBitmap)); | |
| 45 | + if (startIconRes != 0) { | |
| 46 | + Bitmap pointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), startIconRes), 40, 40); | |
| 47 | + OverlayOptions startOptions = new MarkerOptions().position(points.get(0)).icon(BitmapDescriptorFactory.fromBitmap(pointBitmap)); | |
| 46 | 48 | // .zIndex(9).draggable(true); |
| 47 | - return baiduMap.addOverlay(startOptions); | |
| 49 | + return baiduMap.addOverlay(startOptions); | |
| 50 | + } else { | |
| 51 | + return null; | |
| 52 | + } | |
| 48 | 53 | } |
| 49 | 54 | |
| 50 | 55 | LatLng startPoint; |
| ... | ... | @@ -58,22 +63,33 @@ public class MyMapUtil { |
| 58 | 63 | } |
| 59 | 64 | |
| 60 | 65 | // 添加起点图标 |
| 61 | - Bitmap startPointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), startIconRes), 40, 40); | |
| 62 | - OverlayOptions startOptions = new MarkerOptions() | |
| 63 | - .position(startPoint).icon(BitmapDescriptorFactory.fromBitmap(startPointBitmap)); | |
| 66 | + Bitmap startPointBitmap = null; | |
| 67 | + OverlayOptions startOptions = null; | |
| 68 | + if (startIconRes != 0) { | |
| 69 | + startPointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), startIconRes), 40, 40); | |
| 70 | + startOptions = new MarkerOptions().perspective(false).animateType(MarkerOptions.MarkerAnimateType.grow) | |
| 71 | + .position(startPoint).icon(BitmapDescriptorFactory.fromBitmap(startPointBitmap)); | |
| 72 | + } | |
| 64 | 73 | // .zIndex(9).draggable(true); |
| 65 | 74 | // 添加终点图标 |
| 66 | - Bitmap endPointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), endIconRes), 40, 40); | |
| 67 | - OverlayOptions endOptions = new MarkerOptions().position(endPoint) | |
| 68 | - .icon(BitmapDescriptorFactory.fromBitmap(endPointBitmap)); | |
| 75 | + Bitmap endPointBitmap = null; | |
| 76 | + OverlayOptions endOptions = null; | |
| 77 | + if (endIconRes != 0) { | |
| 78 | + endPointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), endIconRes), 40, 40); | |
| 79 | + endOptions = new MarkerOptions().position(endPoint).perspective(false).animateType(MarkerOptions.MarkerAnimateType.grow) | |
| 80 | + .icon(BitmapDescriptorFactory.fromBitmap(endPointBitmap)); | |
| 81 | + } | |
| 69 | 82 | // .zIndex(9).draggable(true); |
| 70 | 83 | |
| 71 | 84 | // 添加路线(轨迹) |
| 72 | 85 | OverlayOptions polylineOptions = new PolylineOptions().width(10) |
| 73 | 86 | .color(context.getResources().getColor(lineColor)).points(points); |
| 74 | - | |
| 75 | - baiduMap.addOverlay(startOptions); | |
| 76 | - baiduMap.addOverlay(endOptions); | |
| 87 | + if (startOptions != null) { | |
| 88 | + baiduMap.addOverlay(startOptions); | |
| 89 | + } | |
| 90 | + if (endOptions != null) { | |
| 91 | + baiduMap.addOverlay(endOptions); | |
| 92 | + } | |
| 77 | 93 | return baiduMap.addOverlay(polylineOptions); |
| 78 | 94 | } |
| 79 | 95 | |
| ... | ... | @@ -82,7 +98,6 @@ public class MyMapUtil { |
| 82 | 98 | */ |
| 83 | 99 | public static Overlay drawServerLineTrack(Context context, BaiduMap baiduMap, List<LatLng> points, SortType sortType, int lineColor, int startIconRes, int endIconRes) { |
| 84 | 100 | // 绘制新覆盖物前,清空之前的覆盖物 |
| 85 | - baiduMap.clear(); | |
| 86 | 101 | if (points == null || points.size() == 0) { |
| 87 | 102 | return null; |
| 88 | 103 | } |
| ... | ... | @@ -107,12 +122,19 @@ public class MyMapUtil { |
| 107 | 122 | // 添加起点图标 |
| 108 | 123 | Bitmap startPointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), startIconRes), 40, 40); |
| 109 | 124 | OverlayOptions startOptions = new MarkerOptions() |
| 110 | - .position(startPoint).icon(BitmapDescriptorFactory.fromBitmap(startPointBitmap)); | |
| 125 | + .position(startPoint) | |
| 126 | + .icon(BitmapDescriptorFactory.fromBitmap(startPointBitmap)) | |
| 127 | + .perspective(false) | |
| 128 | + .animateType(MarkerOptions.MarkerAnimateType.grow) | |
| 129 | + ; | |
| 111 | 130 | // .zIndex(9).draggable(true); |
| 112 | 131 | // 添加终点图标 |
| 113 | 132 | Bitmap endPointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), endIconRes), 40, 40); |
| 114 | - OverlayOptions endOptions = new MarkerOptions().position(endPoint) | |
| 115 | - .icon(BitmapDescriptorFactory.fromBitmap(endPointBitmap)); | |
| 133 | + OverlayOptions endOptions = new MarkerOptions() | |
| 134 | + .position(endPoint) | |
| 135 | + .icon(BitmapDescriptorFactory.fromBitmap(endPointBitmap)) | |
| 136 | + .perspective(false) | |
| 137 | + .animateType(MarkerOptions.MarkerAnimateType.grow); | |
| 116 | 138 | // .zIndex(9).draggable(true); |
| 117 | 139 | |
| 118 | 140 | // 添加路线(轨迹) |
| ... | ... | @@ -131,6 +153,18 @@ public class MyMapUtil { |
| 131 | 153 | return baiduMap.addOverlay(polylineOptions); |
| 132 | 154 | } |
| 133 | 155 | |
| 156 | + public static Overlay drawMapLineRoutePoint(Context context, BaiduMap baiduMap, List<RoutePoint> points, int lineColor) { | |
| 157 | + List<LatLng> latLngs = new ArrayList<>(); | |
| 158 | + for (RoutePoint routePoint : points) { | |
| 159 | + if (routePoint != null && routePoint.getLat() != 0 && routePoint.getLng() != 0) { | |
| 160 | + latLngs.add(new LatLng(routePoint.getLat(), routePoint.getLng())); | |
| 161 | + } | |
| 162 | + } | |
| 163 | + OverlayOptions polylineOptions = new PolylineOptions().width(10) | |
| 164 | + .color(context.getResources().getColor(lineColor)).points(latLngs); | |
| 165 | + return baiduMap.addOverlay(polylineOptions); | |
| 166 | + } | |
| 167 | + | |
| 134 | 168 | public static double pi = 3.1415926535897932384626; |
| 135 | 169 | public static double a = 6378245.0; |
| 136 | 170 | public static double ee = 0.00669342162296594323; |
| ... | ... | @@ -257,7 +291,6 @@ public class MyMapUtil { |
| 257 | 291 | } |
| 258 | 292 | |
| 259 | 293 | |
| 260 | - | |
| 261 | 294 | /*****************************************************地理围栏***************************************************************/ |
| 262 | 295 | /** |
| 263 | 296 | * 地球半径 |
| ... | ... | @@ -437,36 +470,38 @@ public class MyMapUtil { |
| 437 | 470 | /** |
| 438 | 471 | * luming |
| 439 | 472 | * 点到边的最短距离 |
| 473 | + * | |
| 440 | 474 | * @param pointP |
| 441 | 475 | * @param pointA |
| 442 | 476 | * @param pointB |
| 443 | 477 | * @return |
| 444 | 478 | */ |
| 445 | - public static double minDistanceToLine(LatLng pointP, LatLng pointA, LatLng pointB){ | |
| 446 | - double pa = getDistance(pointP,pointA); | |
| 447 | - double pb = getDistance(pointP,pointB); | |
| 448 | - double ab = getDistance(pointA,pointB); | |
| 479 | + public static double minDistanceToLine(LatLng pointP, LatLng pointA, LatLng pointB) { | |
| 480 | + double pa = getDistance(pointP, pointA); | |
| 481 | + double pb = getDistance(pointP, pointB); | |
| 482 | + double ab = getDistance(pointA, pointB); | |
| 449 | 483 | |
| 450 | - if((Math.pow(pa,2) + Math.pow(ab,2)) <= Math.pow(pb,2) ){ | |
| 484 | + if ((Math.pow(pa, 2) + Math.pow(ab, 2)) <= Math.pow(pb, 2)) { | |
| 451 | 485 | return pa; |
| 452 | 486 | } |
| 453 | - if((Math.pow(pb,2) + Math.pow(ab,2)) <= Math.pow(pa,2) ){ | |
| 487 | + if ((Math.pow(pb, 2) + Math.pow(ab, 2)) <= Math.pow(pa, 2)) { | |
| 454 | 488 | return pb; |
| 455 | 489 | } |
| 456 | 490 | |
| 457 | - double p = (pa + pb + ab) / 2 ; | |
| 458 | - double s = Math.sqrt(p*(p-pa)*(p-pb)*(p-ab)); | |
| 491 | + double p = (pa + pb + ab) / 2; | |
| 492 | + double s = Math.sqrt(p * (p - pa) * (p - pb) * (p - ab)); | |
| 459 | 493 | |
| 460 | - return (2*s/ab); | |
| 494 | + return (2 * s / ab); | |
| 461 | 495 | } |
| 462 | 496 | |
| 463 | 497 | /** |
| 464 | 498 | * 通过经纬度获取距离(单位:米) |
| 499 | + * | |
| 465 | 500 | * @param location1 |
| 466 | 501 | * @param location2 |
| 467 | 502 | * @return |
| 468 | 503 | */ |
| 469 | - public static double getDistance(LatLng location1,LatLng location2) { | |
| 504 | + public static double getDistance(LatLng location1, LatLng location2) { | |
| 470 | 505 | double lat1 = location1.latitude; |
| 471 | 506 | double lat2 = location2.latitude; |
| 472 | 507 | double lng1 = location1.longitude; |
| ... | ... | @@ -480,7 +515,67 @@ public class MyMapUtil { |
| 480 | 515 | * Math.pow(Math.sin(b / 2), 2))); |
| 481 | 516 | s = s * EARTH_RADIUS; |
| 482 | 517 | s = Math.round(s * 10000d) / 10000d; |
| 483 | - s = s*1000; | |
| 518 | + s = s * 1000; | |
| 484 | 519 | return s; |
| 485 | 520 | } |
| 521 | + | |
| 522 | + | |
| 523 | + /** | |
| 524 | + * 地图平滑算法 | |
| 525 | + * | |
| 526 | + * @param inPoint | |
| 527 | + * @return | |
| 528 | + */ | |
| 529 | + public static List<RoutePoint> optimizePoints(List<RoutePoint> inPoint) { | |
| 530 | + int size = inPoint.size(); | |
| 531 | + List<RoutePoint> outPoint; | |
| 532 | + | |
| 533 | + int i; | |
| 534 | + if (size < 5) { | |
| 535 | + return inPoint; | |
| 536 | + } else { | |
| 537 | + // Latitude | |
| 538 | + inPoint.get(0) | |
| 539 | + .setLat((3.0 * inPoint.get(0).getLat() + 2.0 | |
| 540 | + * inPoint.get(1).getLat() + inPoint.get(2).getLat() - inPoint | |
| 541 | + .get(4).getLat()) / 5.0); | |
| 542 | + inPoint.get(1) | |
| 543 | + .setLat((4.0 * inPoint.get(0).getLat() + 3.0 | |
| 544 | + * inPoint.get(1).getLat() + 2 | |
| 545 | + * inPoint.get(2).getLat() + inPoint.get(3).getLat()) / 10.0); | |
| 546 | + | |
| 547 | + inPoint.get(size - 2).setLat( | |
| 548 | + (4.0 * inPoint.get(size - 1).getLat() + 3.0 | |
| 549 | + * inPoint.get(size - 2).getLat() + 2 | |
| 550 | + * inPoint.get(size - 3).getLat() + inPoint.get( | |
| 551 | + size - 4).getLat()) / 10.0); | |
| 552 | + inPoint.get(size - 1).setLat( | |
| 553 | + (3.0 * inPoint.get(size - 1).getLat() + 2.0 | |
| 554 | + * inPoint.get(size - 2).getLat() | |
| 555 | + + inPoint.get(size - 3).getLat() - inPoint.get( | |
| 556 | + size - 5).getLat()) / 5.0); | |
| 557 | + | |
| 558 | + // Longitude | |
| 559 | + inPoint.get(0) | |
| 560 | + .setLng((3.0 * inPoint.get(0).getLng() + 2.0 | |
| 561 | + * inPoint.get(1).getLng() + inPoint.get(2).getLng() - inPoint | |
| 562 | + .get(4).getLng()) / 5.0); | |
| 563 | + inPoint.get(1) | |
| 564 | + .setLng((4.0 * inPoint.get(0).getLng() + 3.0 | |
| 565 | + * inPoint.get(1).getLng() + 2 | |
| 566 | + * inPoint.get(2).getLng() + inPoint.get(3).getLng()) / 10.0); | |
| 567 | + | |
| 568 | + inPoint.get(size - 2).setLng( | |
| 569 | + (4.0 * inPoint.get(size - 1).getLng() + 3.0 | |
| 570 | + * inPoint.get(size - 2).getLng() + 2 | |
| 571 | + * inPoint.get(size - 3).getLng() + inPoint.get( | |
| 572 | + size - 4).getLng()) / 10.0); | |
| 573 | + inPoint.get(size - 1).setLng( | |
| 574 | + (3.0 * inPoint.get(size - 1).getLng() + 2.0 | |
| 575 | + * inPoint.get(size - 2).getLng() | |
| 576 | + + inPoint.get(size - 3).getLng() - inPoint.get( | |
| 577 | + size - 5).getLng()) / 5.0); | |
| 578 | + } | |
| 579 | + return inPoint; | |
| 580 | + } | |
| 486 | 581 | } | ... | ... |
moudle_pedometer/src/main/res/drawable-hdpi/icon_end.png
0 → 100644
6.57 KB
moudle_pedometer/src/main/res/drawable-hdpi/icon_end.webp deleted
100644 → 0
No preview for this file type
moudle_pedometer/src/main/res/drawable-hdpi/icon_start.png
0 → 100644
5.93 KB
moudle_pedometer/src/main/res/drawable-hdpi/icon_start.webp deleted
100644 → 0
No preview for this file type
moudle_pedometer/src/main/res/layout/fragment_run_main.xml
| ... | ... | @@ -138,7 +138,7 @@ |
| 138 | 138 | android:layout_height="wrap_content" |
| 139 | 139 | android:layout_marginTop="5dp" |
| 140 | 140 | android:gravity="center" |
| 141 | - android:text="时速" | |
| 141 | + android:text="配速" | |
| 142 | 142 | android:textColor="@color/text_gray" |
| 143 | 143 | android:textSize="17sp" |
| 144 | 144 | android:textStyle="bold" /> |
| ... | ... | @@ -205,7 +205,7 @@ |
| 205 | 205 | android:layout_height="wrap_content" |
| 206 | 206 | android:layout_marginTop="5dp" |
| 207 | 207 | android:gravity="center" |
| 208 | - android:text="步数" | |
| 208 | + android:text="步" | |
| 209 | 209 | android:textColor="@color/text_gray" |
| 210 | 210 | android:textSize="17sp" |
| 211 | 211 | android:textStyle="bold" /> | ... | ... |
moudle_pedometer/src/main/res/layout/layout_finish_running_route.xml
| ... | ... | @@ -48,6 +48,7 @@ |
| 48 | 48 | android:textSize="14sp" /> |
| 49 | 49 | |
| 50 | 50 | <TextView |
| 51 | + android:id="@+id/tv_start_point" | |
| 51 | 52 | android:layout_width="wrap_content" |
| 52 | 53 | android:layout_height="wrap_content" |
| 53 | 54 | android:layout_marginLeft="10dp" |
| ... | ... | @@ -84,6 +85,7 @@ |
| 84 | 85 | android:textSize="14sp" /> |
| 85 | 86 | |
| 86 | 87 | <TextView |
| 88 | + android:id="@+id/tv_end_point" | |
| 87 | 89 | android:layout_width="wrap_content" |
| 88 | 90 | android:layout_height="wrap_content" |
| 89 | 91 | android:layout_marginLeft="10dp" |
| ... | ... | @@ -102,7 +104,7 @@ |
| 102 | 104 | <LinearLayout |
| 103 | 105 | android:layout_width="match_parent" |
| 104 | 106 | android:layout_height="wrap_content" |
| 105 | - android:layout_marginTop="-17dp" | |
| 107 | + android:layout_marginTop="-15dp" | |
| 106 | 108 | android:gravity="center_vertical"> |
| 107 | 109 | |
| 108 | 110 | <View |
| ... | ... | @@ -117,6 +119,7 @@ |
| 117 | 119 | android:orientation="vertical"> |
| 118 | 120 | |
| 119 | 121 | <TextView |
| 122 | + android:id="@+id/tv_timer" | |
| 120 | 123 | android:layout_width="wrap_content" |
| 121 | 124 | android:layout_height="wrap_content" |
| 122 | 125 | android:layout_marginLeft="10dp" |
| ... | ... | @@ -128,7 +131,7 @@ |
| 128 | 131 | <TextView |
| 129 | 132 | android:layout_width="wrap_content" |
| 130 | 133 | android:layout_height="wrap_content" |
| 131 | - android:layout_marginLeft="10dp" | |
| 134 | + android:layout_marginLeft="11dp" | |
| 132 | 135 | android:text="跑步记录时长" |
| 133 | 136 | android:textColor="@color/text_gray" |
| 134 | 137 | android:textSize="12sp" /> | ... | ... |
moudle_pedometer/src/main/res/layout/layout_finish_step.xml
| ... | ... | @@ -28,10 +28,11 @@ |
| 28 | 28 | <LinearLayout |
| 29 | 29 | android:layout_width="match_parent" |
| 30 | 30 | android:layout_height="match_parent" |
| 31 | - android:paddingBottom="10dp" | |
| 32 | - android:gravity="center"> | |
| 31 | + android:gravity="center" | |
| 32 | + android:paddingBottom="10dp"> | |
| 33 | 33 | |
| 34 | 34 | <TextView |
| 35 | + android:id="@+id/tv_step" | |
| 35 | 36 | android:layout_width="wrap_content" |
| 36 | 37 | android:layout_height="wrap_content" |
| 37 | 38 | android:text="1233" | ... | ... |
moudle_pedometer/src/main/res/layout/layout_finish_user_info.xml
| ... | ... | @@ -13,6 +13,7 @@ |
| 13 | 13 | android:orientation="vertical"> |
| 14 | 14 | |
| 15 | 15 | <TextView |
| 16 | + android:id="@+id/tv_user_nickName" | |
| 16 | 17 | android:layout_width="wrap_content" |
| 17 | 18 | android:layout_height="wrap_content" |
| 18 | 19 | android:layout_marginLeft="80dp" |
| ... | ... | @@ -33,6 +34,7 @@ |
| 33 | 34 | android:orientation="vertical"> |
| 34 | 35 | |
| 35 | 36 | <TextView |
| 37 | + android:id="@+id/tv_street_name" | |
| 36 | 38 | android:layout_width="wrap_content" |
| 37 | 39 | android:layout_height="wrap_content" |
| 38 | 40 | android:layout_marginLeft="15dp" |
| ... | ... | @@ -42,6 +44,7 @@ |
| 42 | 44 | android:textSize="15sp" /> |
| 43 | 45 | |
| 44 | 46 | <TextView |
| 47 | + android:id="@+id/tv_date" | |
| 45 | 48 | android:layout_width="wrap_content" |
| 46 | 49 | android:layout_height="wrap_content" |
| 47 | 50 | android:layout_marginLeft="15dp" |
| ... | ... | @@ -57,6 +60,7 @@ |
| 57 | 60 | android:gravity="right|bottom"> |
| 58 | 61 | |
| 59 | 62 | <TextView |
| 63 | + android:id="@+id/tv_distance" | |
| 60 | 64 | android:layout_width="wrap_content" |
| 61 | 65 | android:layout_height="wrap_content" |
| 62 | 66 | android:layout_marginRight="10dp" |
| ... | ... | @@ -95,6 +99,7 @@ |
| 95 | 99 | android:orientation="vertical"> |
| 96 | 100 | |
| 97 | 101 | <TextView |
| 102 | + android:id="@+id/tv_speed" | |
| 98 | 103 | android:layout_width="wrap_content" |
| 99 | 104 | android:layout_height="wrap_content" |
| 100 | 105 | android:text="34'33''" |
| ... | ... | @@ -119,6 +124,7 @@ |
| 119 | 124 | android:orientation="vertical"> |
| 120 | 125 | |
| 121 | 126 | <TextView |
| 127 | + android:id="@+id/tv_timer" | |
| 122 | 128 | android:layout_width="wrap_content" |
| 123 | 129 | android:layout_height="wrap_content" |
| 124 | 130 | android:text="00:00:00" |
| ... | ... | @@ -140,7 +146,7 @@ |
| 140 | 146 | </LinearLayout> |
| 141 | 147 | |
| 142 | 148 | <com.qmuiteam.qmui.widget.QMUIRadiusImageView |
| 143 | - android:id="@+id/qm_iv1" | |
| 149 | + android:id="@+id/qm_iv_icon" | |
| 144 | 150 | android:layout_width="60dp" |
| 145 | 151 | android:layout_height="60dp" |
| 146 | 152 | android:layout_marginLeft="10dp" | ... | ... |
moudle_pedometer/src/main/res/values/strings.xml
| ... | ... | @@ -44,5 +44,8 @@ |
| 44 | 44 | <string name="layout_run_detail_rank_person_finish">人已完成</string> |
| 45 | 45 | <string name="layout_run_detail_street_introduce_title">路线介绍</string> |
| 46 | 46 | <string name="layout_run_detail_street_introduce_map">路线地图</string> |
| 47 | + <string name="loc_check_internet">定位失败,请您检查您的网络状态!</string> | |
| 48 | + <string name="loc_open_gps">定位失败,建议您打开GPS!</string> | |
| 49 | + <string name="loc_open_wifi">定位失败,建议您打开Wi-Fi!</string> | |
| 47 | 50 | <!----> |
| 48 | 51 | </resources> | ... | ... |