Commit c386c2daba19ade62e79bf81c2267f6668cbead2

Authored by 杨帅
2 parents df1d278c 9414c796

Merge branch 'master' of http://bj.gitlab.cnlive.com/cnlive-team/ModulePedometer

# Conflicts:
#	moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunRaceDetailFragmentView.java
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunRaceDetailFragmentView.java
1   -setImportPoints
2 1 \ No newline at end of file
  2 +import android.content.Context;
  3 +import android.content.Intent;
  4 +import android.graphics.Bitmap;
  5 +import android.graphics.BitmapFactory;
  6 +import android.hardware.Sensor;
  7 +import android.hardware.SensorEvent;
  8 +import android.hardware.SensorEventListener;
  9 +import android.hardware.SensorManager;
  10 +import android.os.SystemClock;
  11 +import android.support.v4.content.ContextCompat;
  12 +import android.text.TextUtils;
  13 +import android.util.Log;
  14 +import android.view.View;
  15 +import android.view.ViewTreeObserver;
  16 +import android.widget.LinearLayout;
  17 +import android.widget.Toast;
  18 +
  19 +import com.alibaba.android.arouter.launcher.ARouter;
  20 +import com.baidu.location.BDAbstractLocationListener;
  21 +import com.baidu.location.BDLocation;
  22 +import com.baidu.location.LocationClient;
  23 +import com.baidu.location.LocationClientOption;
  24 +import com.baidu.mapapi.map.BaiduMap;
  25 +import com.baidu.mapapi.map.BitmapDescriptor;
  26 +import com.baidu.mapapi.map.BitmapDescriptorFactory;
  27 +import com.baidu.mapapi.map.MapStatus;
  28 +import com.baidu.mapapi.map.MapStatusUpdate;
  29 +import com.baidu.mapapi.map.MapStatusUpdateFactory;
  30 +import com.baidu.mapapi.map.MapView;
  31 +import com.baidu.mapapi.map.MarkerOptions;
  32 +import com.baidu.mapapi.map.MyLocationConfiguration;
  33 +import com.baidu.mapapi.map.MyLocationData;
  34 +import com.baidu.mapapi.map.UiSettings;
  35 +import com.baidu.mapapi.model.LatLng;
  36 +import com.baidu.mapapi.search.route.RoutePlanSearch;
  37 +import com.baidu.mapapi.utils.DistanceUtil;
  38 +import com.baidu.trace.LBSTraceClient;
  39 +import com.baidu.trace.model.SortType;
  40 +import com.cnlive.libs.base.application.AppConfig;
  41 +import com.cnlive.libs.base.util.StatusBarUtil2;
  42 +import com.cnlive.moudle.pedometer.commonInfo.CommonInfo;
  43 +import com.cnlive.moudle.pedometer.model.Constant;
  44 +import com.cnlive.moudle.pedometer.net.bean.RunRaceDetailInfo;
  45 +import com.cnlive.moudle.pedometer.service.KeepLiveService;
  46 +import com.cnlive.moudle.pedometer.service.StepService;
  47 +import com.cnlive.moudle.pedometer.sql.entity.UserStepEntity;
  48 +import com.cnlive.moudle.pedometer.ui.activity.PedometerMainActivity;
  49 +import com.cnlive.moudle.pedometer.ui.activity.RaceRecordActivity;
  50 +import com.cnlive.moudle.pedometer.ui.activity.RegistrationInfoActivity;
  51 +import com.cnlive.moudle.pedometer.ui.activity.TakePartActivity;
  52 +import com.cnlive.moudle.pedometer.ui.fragment.RunRaceDetailFragment;
  53 +import com.cnlive.moudle.pedometer.ui.widget.SelectDialog;
  54 +import com.cnlive.moudle.pedometer.ui.widget.TipDialog;
  55 +import com.cnlive.moudle.pedometer.utils.BitmapUtil;
  56 +import com.cnlive.moudle.pedometer.utils.GsonUtil;
  57 +import com.cnlive.moudle.pedometer.utils.MyMapUtil;
  58 +import com.cnlive.moudle.pedometer.utils.QMUITipDialogUtil;
  59 +import com.cnlive.moudle.pedometer.utils.ScreenUtil;
  60 +import com.cnlive.moudle.pedometer.utils.ServiceUtils;
  61 +import com.cnlive.moudle.pedometer.utils.StepUtil;
  62 +import com.cnlive.moudle.pedometer.utils.TimeUtil;
  63 +import com.cnlive.strike.application.GlideApp;
  64 +import com.example.moudle_pedometer.R;
  65 +import com.hannesdorfmann.mosby3.mvp.MvpView;
  66 +import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
  67 +import com.sothree.slidinguppanel.SlidingUpPanelLayout;
  68 +
  69 +import java.util.ArrayList;
  70 +import java.util.List;
  71 +
  72 +public class RunRaceDetailFragmentView implements MvpView, SensorEventListener {
  73 + private static final String TAG = "RunRaceDetailView";
  74 +
  75 + private RunRaceDetailFragment fragment;
  76 + private BaiduMap baiduMap;
  77 + private MapView mMapView;
  78 + private UiSettings mUiSettings;
  79 + private MyLocationConfiguration.LocationMode mCurrentMode;//定位模式
  80 + private BitmapDescriptor mCurrentMarker;//定位图标
  81 + private static int accuracyCircleFillColor;
  82 + private static int accuracyCircleStrokeColor;
  83 + private static MyLocationData followMyLocation;
  84 + boolean isFirstLoc = true; // 是否首次定位
  85 + private MarkerOptions currentMark;
  86 + private MarkerOptions endMark;
  87 + private MarkerOptions startMark;
  88 +
  89 + private LatLng firstLatLng;
  90 + private Double lastX = 0.0;
  91 + private int mCurrentDirection = 0;
  92 + // private double mCurrentLat = 0.0;
  93 +// private double mCurrentLon = 0.0;
  94 + private float mCurrentAccracy;
  95 + // 定位相关
  96 + private LocationClient mLocClient;
  97 + public MyLocationListenner myListener = new MyLocationListenner();
  98 + private final int DEFULT_ZOOM = 17;
  99 + private RoutePlanSearch routePlanSearch = null; // 路线规划
  100 + private final int START_MARK = 0;//起始点
  101 + private final int END_MARK = 1;//终止点
  102 + private LatLng startLatLng;//起始点
  103 + public RunRaceDetailInfo runRaceDetailInfo;
  104 + private UserStepEntity userStepEntity;
  105 + private boolean isDifferentStreet = false;
  106 + private LBSTraceClient mClient = null;
  107 + public LatLng endLatLng;//用于终点判断
  108 + private boolean isChangeMapState = true;//上滑卡片是否缩放地图与倾斜
  109 + private float initZoom = 0;
  110 + private final float INIT_MAP_OVERLOOK = -40f;//地图倾斜角度
  111 + private final float DEFAULT_MAP_AUTO_ZOOM = -0.8f;//根据点位,自动缩放的比例
  112 + private List<LatLng> queryResultPoints;//查询到的历史轨迹
  113 +
  114 + public RunRaceDetailFragmentView(RunRaceDetailFragment fragment) {
  115 + this.fragment = fragment;
  116 + }
  117 +
  118 + public Context getContext() {
  119 + return fragment == null ? null : fragment.getActivity();
  120 + }
  121 +
  122 +
  123 + public void initView(RunRaceDetailInfo runRaceDetailInfo) {
  124 + if (fragment.getActivity() == null) {
  125 + return;
  126 + }
  127 + queryResultPoints = new ArrayList<>();
  128 + this.runRaceDetailInfo = runRaceDetailInfo;
  129 + //轨迹开始时间
  130 + long startTime = 0;
  131 + //轨迹结束时间
  132 + long endTime = 0;
  133 + if (!TextUtils.isEmpty(runRaceDetailInfo.getStartTime()) && !TextUtils.isEmpty(runRaceDetailInfo.getEndTime()) && !TextUtils.isEmpty(runRaceDetailInfo.getEntityName())) {
  134 + startTime = Long.parseLong(runRaceDetailInfo.getStartTime());
  135 + endTime = Long.parseLong(runRaceDetailInfo.getEndTime());
  136 + //todo 注意后续查询历史轨迹的时候,必须查数据库中的时间,因为涉及到历史运动恢复,所以不能用这个sp文件中的,这里设置,只是为了在服务启动成功后,
  137 +
  138 + mClient = new LBSTraceClient(getContext());
  139 + //获取轨迹
  140 + if (mClient != null) {
  141 + MyMapUtil.queryHistoryTrace(getContext(), mClient, runRaceDetailInfo.getEntityName(), startTime, endTime, new MyMapUtil.CallBack() {
  142 + @Override
  143 + public void success(List<LatLng> resultPoints) {
  144 + if (resultPoints != null && resultPoints.size() > 1) {
  145 + queryResultPoints.clear();
  146 + queryResultPoints.addAll(resultPoints);
  147 + startLatLng = resultPoints.get(0);
  148 + endLatLng = resultPoints.get(resultPoints.size() - 1);
  149 + MyMapUtil.drawServerLineTrack(getContext(), baiduMap, resultPoints, SortType.asc, R.color.green_round, R.drawable.icon_start, R.drawable.icon_end);
  150 +// //自动计算地图缩放
  151 + //设置地图自动缩放
  152 + initZoom = MyMapUtil.setMapAutoZoom(baiduMap, resultPoints, -1.5f);
  153 +
  154 + }
  155 + }
  156 + });
  157 +
  158 + }
  159 + //
  160 + }
  161 +
  162 + //显示地图
  163 + fragment.binding.mapView.setVisibility(View.VISIBLE);
  164 + //显示底部滑动卡片
  165 +// fragment.binding.slidingLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
  166 + //隐藏空视图
  167 + fragment.binding.emptyLayout.setVisibility(View.GONE);
  168 + //显示立即报名按钮
  169 +// fragment.binding.includeStreet.rlStartBtn.setVisibility(View.VISIBLE);
  170 + //设置底部卡片第一次可滑动的位置
  171 + fragment.binding.slidingLayout.setAnchorPoint(0.6f);
  172 + fragment.binding.slidingLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {
  173 + @Override
  174 + public void onPanelSlide(View panel, float slideOffset) {
  175 + //设置顶层卡片特效
  176 + if (slideOffset > 0.7) {
  177 + double alpha = (255 / (1 - 0.6)) * (slideOffset - 0.6);
  178 + if (alpha > 60) {
  179 + fragment.binding.flTop.getBackground().setAlpha((int) alpha);
  180 + fragment.binding.flTop.setVisibility(View.VISIBLE);
  181 + QMUIStatusBarHelper.setStatusBarDarkMode(fragment.getActivity());
  182 + StatusBarUtil2.setColor(fragment.getActivity(), getContext().getResources().getColor(R.color.run_main_bg), 0);
  183 +
  184 + }
  185 + } else {
  186 + if (fragment.binding.flTop.getVisibility() == View.VISIBLE) {
  187 + QMUIStatusBarHelper.setStatusBarLightMode(fragment.getActivity());
  188 + StatusBarUtil2.setColor(fragment.getActivity(), getContext().getResources().getColor(R.color.white), 0);
  189 + fragment.binding.flTop.setVisibility(View.GONE);
  190 + }
  191 + }
  192 + //设置卡片缩放特效
  193 + if (slideOffset >= 0 && slideOffset <= 1) {
  194 + int leakWidth = (int) (ScreenUtil.dip2px(getContext(), 15) / 0.6);
  195 + LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  196 + int current = (int) (leakWidth * slideOffset);
  197 +// Log.e(TAG, "current: " + current + ",leakWidth:" + leakWidth + ",ScreenUtil:" + ScreenUtil.dip2px(getContext(), 15));
  198 + if (slideOffset == 0) {
  199 + layoutParams.setMargins(ScreenUtil.dip2px(getContext(), 15), 0, ScreenUtil.dip2px(getContext(), 15), 0);
  200 + fragment.binding.includeStreet.llFirstPanelRoot.setLayoutParams(layoutParams);
  201 + fragment.binding.includeStreet.llBottomPanel.setLayoutParams(layoutParams);
  202 + }
  203 + if (leakWidth - ScreenUtil.dip2px(getContext(), current) <= ScreenUtil.dip2px(getContext(), 15)) {
  204 + if (leakWidth - ScreenUtil.dip2px(getContext(), current) >= 0) {
  205 + layoutParams.setMargins(leakWidth - ScreenUtil.dip2px(getContext(), current), 0, leakWidth - ScreenUtil.dip2px(getContext(), current), 0);
  206 + } else {
  207 + layoutParams.setMargins(0, 0, 0, 0);
  208 + }
  209 +
  210 + fragment.binding.includeStreet.llFirstPanelRoot.setLayoutParams(layoutParams);
  211 + fragment.binding.includeStreet.llBottomPanel.setLayoutParams(layoutParams);
  212 + }
  213 +
  214 + }
  215 +
  216 + }
  217 +
  218 + @Override
  219 + public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
  220 + if (newState == SlidingUpPanelLayout.PanelState.EXPANDED) {
  221 + fragment.binding.includeStreet.ivSlideIcon.setVisibility(View.INVISIBLE);
  222 + }
  223 + if (newState == SlidingUpPanelLayout.PanelState.ANCHORED) {
  224 + fragment.binding.includeStreet.ivSlideIcon.setVisibility(View.VISIBLE);
  225 + }
  226 + if (newState == SlidingUpPanelLayout.PanelState.COLLAPSED) {
  227 + fragment.binding.includeStreet.ivSlideIcon.setVisibility(View.VISIBLE);
  228 + }
  229 + if (previousState == SlidingUpPanelLayout.PanelState.ANCHORED && newState == SlidingUpPanelLayout.PanelState.DRAGGING) {
  230 + if (fragment.binding.flTop.getVisibility() != View.VISIBLE) {
  231 + QMUIStatusBarHelper.setStatusBarDarkMode(fragment.getActivity());
  232 + StatusBarUtil2.setColor(fragment.getActivity(), getContext().getResources().getColor(R.color.run_main_bg), 0);
  233 + fragment.binding.flTop.setVisibility(View.VISIBLE);
  234 +
  235 + }
  236 + } else if (previousState == SlidingUpPanelLayout.PanelState.DRAGGING && newState == SlidingUpPanelLayout.PanelState.EXPANDED) {
  237 +
  238 + if (fragment.binding.flTop.getVisibility() != View.VISIBLE) {
  239 + QMUIStatusBarHelper.setStatusBarDarkMode(fragment.getActivity());
  240 + StatusBarUtil2.setColor(fragment.getActivity(), getContext().getResources().getColor(R.color.run_main_bg), 0);
  241 + fragment.binding.flTop.setVisibility(View.VISIBLE);
  242 +
  243 + }
  244 + } else if (previousState == SlidingUpPanelLayout.PanelState.EXPANDED && newState == SlidingUpPanelLayout.PanelState.DRAGGING) {
  245 + QMUIStatusBarHelper.setStatusBarLightMode(fragment.getActivity());
  246 + StatusBarUtil2.setColor(fragment.getActivity(), getContext().getResources().getColor(R.color.white), 0);
  247 + if (fragment.binding.flTop.getVisibility() != View.GONE) {
  248 + fragment.binding.flTop.setVisibility(View.GONE);
  249 + }
  250 + } else if (previousState == SlidingUpPanelLayout.PanelState.DRAGGING && newState == SlidingUpPanelLayout.PanelState.ANCHORED) {
  251 + QMUIStatusBarHelper.setStatusBarLightMode(fragment.getActivity());
  252 + StatusBarUtil2.setColor(fragment.getActivity(), getContext().getResources().getColor(R.color.white), 0);
  253 + if (fragment.binding.flTop.getVisibility() != View.GONE) {
  254 + fragment.binding.flTop.setVisibility(View.GONE);
  255 + }
  256 + }
  257 + //设置地图缩放
  258 + if (newState == SlidingUpPanelLayout.PanelState.ANCHORED) {
  259 + if (isChangeMapState) {
  260 + if (null != baiduMap) {
  261 + if (null != baiduMap.getMapStatus()) {
  262 + MapStatus mapStatus = new MapStatus
  263 + .Builder(baiduMap.getMapStatus())
  264 + .overlook(0)
  265 + .zoom((float) (baiduMap.getMapStatus().zoom - 1.5)).build();
  266 + MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mapStatus);
  267 + baiduMap.animateMapStatus(mapStatusUpdate);
  268 + }
  269 + }
  270 + }
  271 + isChangeMapState = false;
  272 + } else if (newState == SlidingUpPanelLayout.PanelState.COLLAPSED) {
  273 +
  274 + if (null != baiduMap) {
  275 + if (0 == initZoom) {
  276 + initZoom = DEFULT_ZOOM;
  277 + }
  278 + MapStatus mapStatus = new MapStatus
  279 + .Builder(baiduMap.getMapStatus())
  280 + .overlook(INIT_MAP_OVERLOOK)
  281 + .zoom(initZoom)
  282 + .build();
  283 + MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mapStatus);
  284 + baiduMap.animateMapStatus(mapStatusUpdate);
  285 + isChangeMapState = true;
  286 + }
  287 + }
  288 +
  289 + //
  290 +
  291 + }
  292 + });
  293 + //卡片滑动上层标题
  294 + fragment.binding.llTopBack.setOnClickListener(new View.OnClickListener() {
  295 + @Override
  296 + public void onClick(View view) {
  297 + if (getContext() == null) {
  298 + return;
  299 + }
  300 + fragment.getActivity().finish();
  301 + }
  302 + });
  303 + /*************************设置相关页面数据***************************/
  304 + if (runRaceDetailInfo.getFenceId() != null && !TextUtils.isEmpty(runRaceDetailInfo.getFenceId())) {
  305 + //设置围栏ID
  306 + CommonInfo.setFenceId(getContext(), Integer.parseInt(runRaceDetailInfo.getFenceId()));
  307 + }
  308 + //设置标题
  309 + if (!TextUtils.isEmpty(runRaceDetailInfo.getTitle())) {
  310 + fragment.binding.includeStreet.tvRaceTitle.setText(runRaceDetailInfo.getTitle());
  311 + fragment.binding.includeStreet.tvRaceTitle.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
  312 + @Override
  313 + public boolean onPreDraw() {
  314 + Log.e(TAG, "initView: " + fragment.binding.includeStreet.tvRaceTitle.getLineCount());
  315 + fragment.binding.includeStreet.tvRaceTitle.getViewTreeObserver().removeOnPreDrawListener(this);
  316 + return false;
  317 + }
  318 + });
  319 + fragment.binding.slidingLayout.setPanelHeight(ScreenUtil.dip2px(getContext(), 181));
  320 + //根据标题行数,自动调整卡片大小
  321 + fragment.binding.includeStreet.tvRaceTitle.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
  322 + @Override
  323 + public boolean onPreDraw() {
  324 + int line = fragment.binding.includeStreet.tvRaceTitle.getLineCount();
  325 + int height = fragment.binding.includeStreet.tvRaceTitle.getHeight();
  326 + if (line > 1) {
  327 + int avgHeight = height / line;//平局高度
  328 + fragment.binding.slidingLayout.setPanelHeight(ScreenUtil.dip2px(getContext(), 181) + avgHeight * (line - 1));
  329 +
  330 + }
  331 + fragment.binding.includeStreet.tvRaceTitle.getViewTreeObserver().removeOnPreDrawListener(this);
  332 + return false;
  333 + }
  334 + });
  335 + fragment.binding.slidingLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
  336 + }
  337 + //设置活动地点
  338 + if (!TextUtils.isEmpty(runRaceDetailInfo.getAddress())) {
  339 + fragment.binding.includeStreet.tvAddress.setText(runRaceDetailInfo.getAddress());
  340 + //设置活动距离
  341 + if (!TextUtils.isEmpty(runRaceDetailInfo.getMileage())) {
  342 + fragment.binding.includeStreet.tvAddress.append("\t\t全长" + runRaceDetailInfo.getMileage() + "公里");
  343 + }
  344 + }
  345 +
  346 + //设置起点
  347 + if (!TextUtils.isEmpty(runRaceDetailInfo.getStartLocation())) {
  348 + fragment.binding.includeStreet.tvStartAddr.setText(runRaceDetailInfo.getStartLocation());
  349 + }
  350 + //设置终点
  351 + if (!TextUtils.isEmpty(runRaceDetailInfo.getEndLocation())) {
  352 + fragment.binding.includeStreet.tvEndAddr.setText(runRaceDetailInfo.getEndLocation());
  353 + }
  354 + //设置起始报名时间
  355 + if (!TextUtils.isEmpty(TimeUtil.getStampToTime(runRaceDetailInfo.getSign_up_start_time(), "yyyy.MM.dd"))) {
  356 + fragment.binding.includeStreet.tvSignUpStartTime.setText(TimeUtil.getStampToTime(runRaceDetailInfo.getSign_up_start_time(), "yyyy.MM.dd"));
  357 +
  358 + }
  359 + //设置终止报名时间
  360 + if (!TextUtils.isEmpty(TimeUtil.getStampToTime(runRaceDetailInfo.getSign_up_end_time(), "yyyy.MM.dd"))) {
  361 + fragment.binding.includeStreet.tvSignUpEndTime.setText(TimeUtil.getStampToTime(runRaceDetailInfo.getSign_up_end_time(), "yyyy.MM.dd"));
  362 + }
  363 + //设置活动开始时间
  364 + if (!TextUtils.isEmpty(TimeUtil.getStampToTime(runRaceDetailInfo.getStart_time(), "yyyy.MM.dd"))) {
  365 + fragment.binding.includeStreet.tvActiveStartTime.setText(TimeUtil.getStampToTime(runRaceDetailInfo.getStart_time(), "yyyy.MM.dd"));
  366 + }
  367 + //设置活动结束时间
  368 + if (!TextUtils.isEmpty(TimeUtil.getStampToTime(runRaceDetailInfo.getEnd_time(), "yyyy.MM.dd"))) {
  369 + fragment.binding.includeStreet.tvActiveEndTime.setText(TimeUtil.getStampToTime(runRaceDetailInfo.getEnd_time(), "yyyy.MM.dd"));
  370 + }
  371 + //设置活动类型
  372 + if (!TextUtils.isEmpty(runRaceDetailInfo.getEventType())) {
  373 + fragment.binding.includeStreet.tvEventType.setText(runRaceDetailInfo.getEventType());
  374 + }
  375 + //设置参加人数
  376 + fragment.binding.includeStreet.tvSignPerson.setText(runRaceDetailInfo.getSignupNum() + "");
  377 + //设置报名完成的头像
  378 + List<String> joinFaceIcon = runRaceDetailInfo.getFaceUrl();
  379 + if (joinFaceIcon != null && joinFaceIcon.size() > 0) {
  380 + fragment.binding.includeStreet.fiveJoinPerson.setVisibility(View.VISIBLE);
  381 + //设置头像数据
  382 + fragment.binding.includeStreet.fiveJoinPerson.initIconData(joinFaceIcon);
  383 + } else {
  384 + fragment.binding.includeStreet.fiveJoinPerson.setVisibility(View.INVISIBLE);
  385 + }
  386 +
  387 + //判断是否显示个人排行榜
  388 + if (runRaceDetailInfo.isIndividualAchievement()) {
  389 + //显示
  390 + fragment.binding.includePersonScore.llPersonScoreRoot.setVisibility(View.VISIBLE);
  391 + //设置完成人数
  392 + if (!TextUtils.isEmpty(runRaceDetailInfo.getFinishNum())) {
  393 + fragment.binding.includeRank.tvFinishPerson.setText(runRaceDetailInfo.getFinishNum());
  394 + }
  395 + //设置个人行走距离
  396 + if (!TextUtils.isEmpty(runRaceDetailInfo.getUserMileage())) {
  397 + fragment.binding.includePersonScore.tvUserDistance.setText(runRaceDetailInfo.getUserMileage());
  398 + }
  399 + //设置行走步数
  400 + if (!TextUtils.isEmpty(runRaceDetailInfo.getStep())) {
  401 + fragment.binding.includePersonScore.tvStep.setText(runRaceDetailInfo.getStep());
  402 + }
  403 + //设置用时
  404 + if (!TextUtils.isEmpty(runRaceDetailInfo.getEmployTime())) {
  405 + fragment.binding.includePersonScore.tvEmployTime.setText(TimeUtil.stampToChronometer(Long.parseLong(runRaceDetailInfo.getEmployTime())));
  406 + }
  407 + //设置配速
  408 + if (!TextUtils.isEmpty(runRaceDetailInfo.getPace())) {
  409 + fragment.binding.includePersonScore.tvSpeed.setText(runRaceDetailInfo.getPace());
  410 + }
  411 + } else {
  412 + //隐藏
  413 + fragment.binding.includePersonScore.llPersonScoreRoot.setVisibility(View.GONE);
  414 + }
  415 + //设置是否显示排行榜
  416 + if (runRaceDetailInfo.isRanking()) {
  417 + fragment.binding.includeRank.llRankRoot.setVisibility(View.VISIBLE);
  418 + //设置第一名头像
  419 + GlideApp.with(getContext()).load(runRaceDetailInfo.getFirstFaceUrl()).into(fragment.binding.includeRank.ivFirstPersonUrl);
  420 + //设置排行榜头像
  421 + List<String> finishFaceUrl = runRaceDetailInfo.getFinishFaceUrl();
  422 + if (finishFaceUrl != null && finishFaceUrl.size() > 0) {
  423 + fragment.binding.includeRank.fiveRankPerson.initIconData(finishFaceUrl);
  424 + }
  425 + //设置第一名昵称
  426 + if (!TextUtils.isEmpty(runRaceDetailInfo.getFirstName())) {
  427 + fragment.binding.includeRank.tvKingNickName.setText(runRaceDetailInfo.getFirstName());
  428 + }
  429 + //第一名用时
  430 + if (!TextUtils.isEmpty(runRaceDetailInfo.getFirstEmployTime())) {
  431 + fragment.binding.includeRank.tvFirstTime.setText(TimeUtil.stampToChronometer(Long.parseLong(runRaceDetailInfo.getFirstEmployTime())));
  432 + }
  433 + } else {
  434 + fragment.binding.includeRank.llRankRoot.setVisibility(View.GONE);
  435 +
  436 + }
  437 + //设置路线描述
  438 + if (!TextUtils.isEmpty(runRaceDetailInfo.getDescription())) {
  439 + fragment.binding.includeStreetIntroduce.tvStreetIntroduce.setText(runRaceDetailInfo.getDescription());
  440 + }
  441 + //设置路线介绍的图片
  442 + if (!TextUtils.isEmpty(runRaceDetailInfo.getRoadmap())) {
  443 + //设置路线图
  444 + GlideApp.with(getContext()).load(runRaceDetailInfo.getRoadmap()).into(fragment.binding.includeStreetIntroduce.ivRoadMao);
  445 +
  446 + }
  447 + //判断用户是否报名
  448 + if (runRaceDetailInfo.isSignResult()) {
  449 + fragment.binding.rlScrollViewStartBtn.setTag("1");
  450 + fragment.binding.tvRunNow.setText("现在开始");
  451 + fragment.binding.tvGoTip.setVisibility(View.VISIBLE);
  452 + checkStartBtnState();
  453 + } else {
  454 + fragment.binding.rlScrollViewStartBtn.setTag("0");
  455 + fragment.binding.tvRunNow.setText("立即报名");
  456 + fragment.binding.tvGoTip.setVisibility(View.GONE);
  457 + }
  458 +
  459 +// //开始按钮点击事件(未滑动)
  460 +// fragment.binding.includeStreet.rlStartBtn.setOnClickListener(new View.OnClickListener() {
  461 +// @Override
  462 +// public void onClick(View view) {
  463 +// if (fragment.getActivity() == null) {
  464 +// return;
  465 +// }
  466 +// //立即报名
  467 +// if ("0".equals(fragment.binding.includeStreet.rlStartBtn.getTag())) {
  468 +// fragment.binding.includeStreet.rlStartBtn.setTag("1");
  469 +// fragment.binding.includeStreet.tvRunNow.setText(getContext().getResources().getString(R.string.run_race_btn_start_now));
  470 +// fragment.binding.includeStreet.tvGoTip.setVisibility(View.VISIBLE);
  471 +//
  472 +// //设置滑动
  473 +// fragment.binding.rlScrollViewStartBtn.setTag("1");
  474 +// fragment.binding.tvRunNow.setText(getContext().getResources().getString(R.string.run_race_btn_start_now));
  475 +// fragment.binding.tvGoTip.setVisibility(View.VISIBLE);
  476 +// RegistrationInfoActivity.newInstance(fragment.getActivity(), 1001);
  477 +// } else {
  478 +// //计算当前位置与起点坐标距离
  479 +// if (firstLatLng != null && trackPoints != null && trackPoints.size() > 0) {
  480 +// double distance = DistanceUtil.getDistance(firstLatLng, trackPoints.get(0));
  481 +// if (distance < 20) {
  482 +// //开始运动
  483 +// fragment.binding.includeStreet.rlStartBtn.setTag("0");
  484 +// fragment.binding.includeStreet.tvRunNow.setText(getContext().getResources().getString(R.string.run_race_btn_sign_up));
  485 +// fragment.binding.includeStreet.tvGoTip.setVisibility(View.GONE);
  486 +// fragment.getActivity().startActivity(new Intent(getContext(), PedometerMainActivity.class));
  487 +// //设置滑动
  488 +// fragment.binding.rlScrollViewStartBtn.setTag("0");
  489 +// fragment.binding.tvRunNow.setText(getContext().getResources().getString(R.string.run_race_btn_sign_up));
  490 +// fragment.binding.tvGoTip.setVisibility(View.GONE);
  491 +// } else {
  492 +// TipDialog tipDialog = new TipDialog(getContext(), getContext().getResources().getString(R.string.run_race_far_tip), "我知道了", R.color.green_round, new TipDialog.DialogInterface() {
  493 +// @Override
  494 +// public void onClick(TipDialog dialog) {
  495 +// dialog.dismiss();
  496 +// }
  497 +// });
  498 +// tipDialog.show();
  499 +// tipDialog.setCancelable(false);
  500 +// tipDialog.setCanceledOnTouchOutside(false);
  501 +// }
  502 +// }
  503 +// }
  504 +// }
  505 +// });
  506 + //开始按钮点击事件(用户进行滑动滑动)
  507 + fragment.binding.rlScrollViewStartBtn.setOnClickListener(new View.OnClickListener() {
  508 + @Override
  509 + public void onClick(View view) {
  510 + //立即报名
  511 + if ("0".equals(fragment.binding.rlScrollViewStartBtn.getTag())) {
  512 + RegistrationInfoActivity.newInstance(fragment.getActivity());
  513 + }
  514 + //现在开始
  515 + else if ("1".equals(fragment.binding.rlScrollViewStartBtn.getTag())) {
  516 + //先判断是否从百度查询到赛事轨迹
  517 + if (null != endLatLng && null != startLatLng) {
  518 + //开始比较距离
  519 + if (null != firstLatLng) {
  520 + double currentDiatance = DistanceUtil.getDistance(firstLatLng, startLatLng);
  521 + if (currentDiatance < Constant.LOCA_START_POINT_ACCURACY) {
  522 + //设置终点坐标
  523 + runRaceDetailInfo.setEndLatLng(GsonUtil.GsonString(endLatLng));
  524 + startStepService(getContext());
  525 + } else {
  526 + //进行提示
  527 + TipDialog tipDialog = new TipDialog(getContext(), getContext().getResources().getString(R.string.run_race_far_tip), "好的", R.color.green_round, new TipDialog.DialogInterface() {
  528 + @Override
  529 + public void onClick(TipDialog dialog) {
  530 + dialog.dismiss();
  531 + }
  532 + });
  533 + tipDialog.setCancelable(false);
  534 + tipDialog.setCanceledOnTouchOutside(false);
  535 + tipDialog.show();
  536 + }
  537 + }
  538 +
  539 + } else {
  540 + QMUITipDialogUtil.textDialog(getContext(), "正在获取轨迹请稍后...", 1);
  541 + }
  542 + }
  543 + //继续运动
  544 + else if ("2".equals(fragment.binding.rlScrollViewStartBtn.getTag())) {
  545 + if (!isDifferentStreet) {
  546 + SelectDialog continueTipDialog = new SelectDialog(getContext(), "是否继续运动", "否", new SelectDialog.DialogInterface() {
  547 + @Override
  548 + public void onClick(SelectDialog dialog) {
  549 + //清空上次保存数据
  550 + StepUtil.clearRunData(getContext(), CommonInfo.getUserId(getContext()));
  551 + //停止服务
  552 + stopStepService();
  553 + //清除数据
  554 + CommonInfo.resetRace(getContext());
  555 + dialog.dismiss();
  556 + //重置按钮
  557 + fragment.binding.tvRunNow.setText("立即开始");
  558 + fragment.binding.rlScrollViewStartBtn.setTag("1");
  559 + }
  560 + }, "是", new SelectDialog.DialogInterface() {
  561 + @Override
  562 + public void onClick(SelectDialog dialog) {
  563 + dialog.dismiss();
  564 + checkBaiduServiceState();
  565 + }
  566 + });
  567 + continueTipDialog.setCanceledOnTouchOutside(false);
  568 + continueTipDialog.setCancelable(false);
  569 + continueTipDialog.show();
  570 +
  571 + }
  572 +
  573 + //赛事id不同
  574 + else {
  575 + SelectDialog selectDialog = new SelectDialog(getContext(), "您正在参与另一赛事\n是否继续?", "否", new SelectDialog.DialogInterface() {
  576 + @Override
  577 + public void onClick(SelectDialog dialog) {
  578 + dialog.dismiss();
  579 + //清空上次保存数据
  580 + StepUtil.clearRunData(getContext(), CommonInfo.getUserId(getContext()));
  581 + //停止服务
  582 + stopStepService();
  583 + //清除数据
  584 + CommonInfo.resetRace(getContext());
  585 + //更改当前按钮
  586 + fragment.binding.tvRunNow.setText("立即开始");
  587 + fragment.binding.rlScrollViewStartBtn.setTag("1");
  588 +
  589 + }
  590 + }, "是", new SelectDialog.DialogInterface() {
  591 + @Override
  592 + public void onClick(SelectDialog dialog) {
  593 + dialog.dismiss();
  594 + checkBaiduServiceState();
  595 + }
  596 + });
  597 + selectDialog.setCanceledOnTouchOutside(false);
  598 + selectDialog.setCancelable(false);
  599 + selectDialog.show();
  600 + }
  601 + }
  602 + }
  603 + });
  604 + //查看全部成绩点击事件
  605 + fragment.binding.includePersonScore.checkAllCord.setOnClickListener(v -> {
  606 + RaceRecordActivity.newInstance(fragment.getActivity(), runRaceDetailInfo.getTitle());
  607 + });
  608 +
  609 + fragment.binding.includeStreet.fiveJoinPerson.setOnClickListener(v -> {
  610 + TakePartActivity.newInstance(fragment.getActivity());
  611 + });
  612 + //返回按钮
  613 + fragment.binding.ivBack.setOnClickListener(new View.OnClickListener() {
  614 + @Override
  615 + public void onClick(View view) {
  616 + if (fragment.getActivity() == null) {
  617 + return;
  618 + }
  619 + fragment.getActivity().finish();
  620 + }
  621 + });
  622 + //todo 查看排行榜点击
  623 + fragment.binding.includeRank.tvCatAllRank.setOnClickListener(new View.OnClickListener() {
  624 + @Override
  625 + public void onClick(View view) {
  626 + String baseWebUrl = AppConfig.isDebug() ? "http://wjjh5test.cnlive.com/cnSportList.html" : "http://wjjh5.cnlive.com/cnSportList.html";
  627 + ARouter.getInstance().build("/web/WebViewColorActivity")
  628 + .withString("url", baseWebUrl + "?sid=" + CommonInfo.getUserId(fragment.getActivity()) + "&eventId=" + CommonInfo.getStreetId(fragment.getActivity()))
  629 + .withString("title", "排行榜")
  630 + .navigation(fragment.getActivity());
  631 + }
  632 + });
  633 + }
  634 +
  635 + private void checkBaiduServiceState() {
  636 + boolean isRunBaidu = CommonInfo.getIsRunBaiduTraceService(getContext());
  637 + if (isRunBaidu) {
  638 + //判断百度服务是否运行
  639 + if (!ServiceUtils.isServiceRunning(getContext(), "com.baidu.trace.LBSTraceService")) {
  640 + stopStepService();
  641 + startStepService(getContext());
  642 + } else {
  643 + PedometerMainActivity.startActivity(fragment.getActivity(), runRaceDetailInfo);
  644 + }
  645 + } else {
  646 + PedometerMainActivity.startActivity(fragment.getActivity(), runRaceDetailInfo);
  647 + }
  648 + }
  649 +
  650 + private void stopStepService() {
  651 + CommonInfo.setTsRunBaiduTraceService(getContext(), false);
  652 + CommonInfo.setIsRunKeepAliveService(getContext(), false);
  653 + CommonInfo.setIsWriteUserStep(getContext(), false);
  654 + CommonInfo.setIsFirstStepSendTraceTip(getContext(), true);
  655 + if (StepService.mClient != null) {
  656 + StepService.mClient.stopGather(StepService.traceListener);
  657 + }
  658 + fragment.getActivity().stopService(new Intent(fragment.getActivity(), StepService.class));
  659 + }
  660 +
  661 + public void initMap() {
  662 + //隐藏底部滑动卡片
  663 + fragment.binding.slidingLayout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN);
  664 + this.mMapView = fragment.binding.mapView;
  665 + if (baiduMap == null) {
  666 + baiduMap = mMapView.getMap();
  667 + }
  668 + //设置指南针位置
  669 + android.graphics.Point point = new android.graphics.Point(ScreenUtil.getScreenWidth(getContext()) - 80, 80);
  670 + baiduMap.setCompassPosition(point);
  671 +// if (routePlanSearch == null) {
  672 +// routePlanSearch = RoutePlanSearch.newInstance();
  673 +// }
  674 + if (mUiSettings == null) {
  675 + mUiSettings = baiduMap.getUiSettings();
  676 + }
  677 + //设置定位模式, 默认为 LocationMode.NORMAL 普通态
  678 + mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL;
  679 + // 设置定位图标修改为自定义marker
  680 + Bitmap pointBitmap = BitmapUtil.getBitmapFromDp(getContext(), BitmapFactory.decodeResource(getContext().getResources(), R.drawable.rt_ic_location), 50, 50);
  681 + mCurrentMarker = BitmapDescriptorFactory.fromBitmap(pointBitmap);
  682 + //设置定位蓝点精度圆圈的填充颜色为透明色
  683 + accuracyCircleFillColor = getContext().getResources().getColor(R.color.transparent);
  684 + //设置定位蓝点精度圆圈的边框颜色的为透明色
  685 + accuracyCircleStrokeColor = getContext().getResources().getColor(R.color.transparent);
  686 + MyLocationConfiguration locationConfiguration = new MyLocationConfiguration(mCurrentMode,
  687 + true, mCurrentMarker, accuracyCircleFillColor, accuracyCircleStrokeColor);
  688 + //设置样式
  689 + baiduMap.setMyLocationConfiguration(locationConfiguration);
  690 + //启动所有手势
  691 + mUiSettings.setAllGesturesEnabled(true);
  692 + //通过设置enable为true或false 选择是否显示缩放按钮
  693 + mMapView.showZoomControls(false);
  694 + mUiSettings.setEnlargeCenterWithDoubleClickEnable(true);
  695 + //隐藏自带的指南针,改用自定义指南针 杨帅
  696 + baiduMap.getUiSettings().setCompassEnabled(true);
  697 + //显示定位图层
  698 + baiduMap.setMyLocationEnabled(true);
  699 + // 定位初始化
  700 + mLocClient = new LocationClient(getContext());
  701 + mLocClient.registerLocationListener(myListener);
  702 + LocationClientOption option = new LocationClientOption();
  703 + option.setOpenGps(true); // 打开gps
  704 + option.setCoorType("gcj02"); // 设置坐标类型
  705 + //可选,默认false,设置是否开启Gps定位
  706 + option.setOpenGps(true);
  707 + //设置打开自动回调位置模式,该开关打开后,期间只要定位SDK检测到位置变化就会主动回调给开发者,该模式下开发者无需再关心定位间隔是多少,定位SDK本身发现位置变化就会及时回调给开发者
  708 + option.setOpenAutoNotifyMode();
  709 + //可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
  710 + option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
  711 + //可选,设置是否需要地址信息,默认不需要
  712 + option.setIsNeedAddress(true);
  713 + //可选,设置是否需要地址描述
  714 + option.setIsNeedLocationDescribe(true);
  715 + //可选,设置是否需要设备方向结果
  716 + option.setNeedDeviceDirect(false);
  717 + //设置打开自动回调位置模式,该开关打开后,期间只要定位SDK检测到位置变化就会主动回调给开发者
  718 + option.setOpenAutoNotifyMode(3000, 1, LocationClientOption.LOC_SENSITIVITY_HIGHT);
  719 + mLocClient.setLocOption(option);
  720 + mLocClient.start();
  721 + //设置地图加载完毕监听
  722 + baiduMap.setOnMapLoadedCallback(new BaiduMap.OnMapLoadedCallback() {
  723 + @Override
  724 + public void onMapLoaded() {
  725 +//
  726 +
  727 + }
  728 + });
  729 + }
  730 +
  731 +// /**
  732 +// * 开始路线规划
  733 +// */
  734 +// public void searchRouteResult(LatLng StartPoint, LatLng EndPoint, int index, int listSize) {
  735 +//// Log.e(TAG, "searchRouteResult: ");
  736 +// float currentZoom = baiduMap.getMapStatus().zoom;
  737 +// // 设置起终点信息,对于tranist search 来说,城市名无意义
  738 +// PlanNode stNode = PlanNode.withLocation(StartPoint);
  739 +// PlanNode enNode = PlanNode.withLocation(EndPoint);
  740 +// routePlanSearch.setOnGetRoutePlanResultListener(new OnGetRoutePlanResultListener() {
  741 +// @Override
  742 +// public void onGetWalkingRouteResult(WalkingRouteResult walkingRouteResult) {
  743 +// if (fragment.getActivity() == null) {
  744 +// return;
  745 +// }
  746 +// if (walkingRouteResult == null || walkingRouteResult.error != SearchResult.ERRORNO.NO_ERROR) {
  747 +// Toast.makeText(fragment.getActivity(), "抱歉,无法获取路线!", Toast.LENGTH_SHORT).show();
  748 +// }
  749 +// if (walkingRouteResult.error == SearchResult.ERRORNO.AMBIGUOUS_ROURE_ADDR) {
  750 +// // 起终点或途经点地址有岐义,通过以下接口获取建议查询信息
  751 +// return;
  752 +// }
  753 +// List<LatLng> points = new ArrayList<LatLng>();
  754 +// if (walkingRouteResult.getRouteLines() != null) {
  755 +// if (walkingRouteResult.getRouteLines().get(0).getAllStep().get(0).getWayPoints().size() > 0) {
  756 +// //添加起点坐标
  757 +// if (index == 0) {
  758 +// points.add(StartPoint);
  759 +// }
  760 +// for (int i = 0; i < walkingRouteResult.getRouteLines().get(0).getAllStep().size(); i++) {
  761 +// for (int j = 0; j < walkingRouteResult.getRouteLines().get(0).getAllStep().get(i).getWayPoints().size(); j++) {
  762 +// points.add(walkingRouteResult.getRouteLines().get(0).getAllStep().get(i).getWayPoints().get(j));
  763 +// }
  764 +// }
  765 +// }
  766 +// //添加终点坐标
  767 +// if (endLatLng != null) {
  768 +//// points.add(endLatLng);
  769 +// }
  770 +//
  771 +// ArrayList<Integer> traffics = new ArrayList<Integer>();
  772 +// for (int i = 0; i < points.size(); i++) {
  773 +// if (i % 2 == 0) {
  774 +// traffics.add(i);
  775 +// }
  776 +// }
  777 +//
  778 +//
  779 +// if (points.size() > 0) {
  780 +//// if (baiduMap != null) {
  781 +//// baiduMap.clear();
  782 +//// if (endLatLng != null) {
  783 +//// markPoi(endLatLng.latitude, endLatLng.longitude);
  784 +//// }
  785 +//// }
  786 +//
  787 +// //设置折线的属性
  788 +//// OverlayOptions mOverlayOptions = new PolylineOptions()
  789 +//// .width(10)
  790 +//// .color(0xAAFF0000)
  791 +//// .points(points);
  792 +// //设置折线的属性
  793 +// OverlayOptions mOverlayOptions = new PolylineOptions()
  794 +// .width(10)
  795 +// .dottedLine(true)
  796 +// .points(points)
  797 +// .customTextureList(getCustomTextureList())
  798 +// .textureIndex(traffics);//设置纹理列表
  799 +// //在地图上绘制起点
  800 +// if (index == 0) {
  801 +// //显示当前位置图标
  802 +// Bitmap pointBitmap = BitmapUtil.getBitmapFromDp(getContext(), BitmapFactory.decodeResource(getContext().getResources(), R.drawable.icon_start), 30, 30);
  803 +// startMark = new MarkerOptions()
  804 +// .position(StartPoint)
  805 +// .icon(BitmapDescriptorFactory.fromBitmap(pointBitmap));
  806 +//// startMark.anchor(0.5f, 0.55f);
  807 +// baiduMap.addOverlay(startMark);
  808 +// } else if (index == listSize - 1) {
  809 +// //显示当前位置图标
  810 +// Bitmap pointBitmap = BitmapUtil.getBitmapFromDp(getContext(), BitmapFactory.decodeResource(getContext().getResources(), R.drawable.icon_end), 30, 30);
  811 +// endMark = new MarkerOptions()
  812 +// .position(points.get(points.size() - 1))
  813 +// .icon(BitmapDescriptorFactory.fromBitmap(pointBitmap))
  814 +// .perspective(true)
  815 +//// endMark.anchor(0.5f, 0.5f)
  816 +// .perspective(true);
  817 +// baiduMap.addOverlay(endMark);
  818 +// }
  819 +// //mPloyline 折线对象
  820 +// Overlay mPolyline = baiduMap.addOverlay(mOverlayOptions);
  821 +// MapStatus.Builder builder = new MapStatus.Builder();
  822 +// builder.zoom(currentZoom);
  823 +// baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
  824 +//
  825 +// }
  826 +// }
  827 +// }
  828 +//
  829 +// @Override
  830 +// public void onGetTransitRouteResult(TransitRouteResult transitRouteResult) {
  831 +//
  832 +// }
  833 +//
  834 +// @Override
  835 +// public void onGetMassTransitRouteResult(MassTransitRouteResult massTransitRouteResult) {
  836 +//
  837 +// }
  838 +//
  839 +// @Override
  840 +// public void onGetDrivingRouteResult(DrivingRouteResult drivingRouteResult) {
  841 +// if (fragment.getActivity() == null) {
  842 +// return;
  843 +// }
  844 +//
  845 +// if (drivingRouteResult == null || drivingRouteResult.error != SearchResult.ERRORNO.NO_ERROR) {
  846 +// Toast.makeText(fragment.getActivity(), "抱歉,无法获取路线!", Toast.LENGTH_SHORT).show();
  847 +// }
  848 +// if (drivingRouteResult.error == SearchResult.ERRORNO.AMBIGUOUS_ROURE_ADDR) {
  849 +// // 起终点或途经点地址有岐义,通过以下接口获取建议查询信息
  850 +// return;
  851 +// }
  852 +// List<LatLng> points = new ArrayList<LatLng>();
  853 +// if (drivingRouteResult.getRouteLines() != null) {
  854 +// if (drivingRouteResult.getRouteLines().get(0).getAllStep().get(0).getWayPoints().size() > 0) {
  855 +// //添加起点坐标
  856 +// if (followMyLocation != null) {
  857 +// points.add(new LatLng(followMyLocation.latitude, followMyLocation.longitude));
  858 +// }
  859 +// for (int i = 0; i < drivingRouteResult.getRouteLines().get(0).getAllStep().size(); i++) {
  860 +// for (int j = 0; j < drivingRouteResult.getRouteLines().get(0).getAllStep().get(i).getWayPoints().size(); j++) {
  861 +// points.add(drivingRouteResult.getRouteLines().get(0).getAllStep().get(i).getWayPoints().get(j));
  862 +// }
  863 +// }
  864 +// }
  865 +// //添加终点坐标
  866 +// if (endLatLng != null) {
  867 +// points.add(endLatLng);
  868 +// }
  869 +// if (points.size() > 0) {
  870 +// if (baiduMap != null) {
  871 +// baiduMap.clear();
  872 +// if (endLatLng != null) {
  873 +// markPoi(endLatLng.latitude, endLatLng.longitude);
  874 +// }
  875 +// }
  876 +//
  877 +// //设置折线的属性
  878 +// OverlayOptions mOverlayOptions = new PolylineOptions()
  879 +// .width(10)
  880 +// .color(0xAAFF0000)
  881 +// .points(points);
  882 +// //在地图上绘制折线
  883 +// //mPloyline 折线对象
  884 +// Overlay mPolyline = baiduMap.addOverlay(mOverlayOptions);
  885 +// MapStatus.Builder builder = new MapStatus.Builder();
  886 +// builder.zoom(currentZoom);
  887 +// baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
  888 +//
  889 +// }
  890 +// }
  891 +// }
  892 +//
  893 +// @Override
  894 +// public void onGetIndoorRouteResult(IndoorRouteResult indoorRouteResult) {
  895 +//
  896 +// }
  897 +//
  898 +// @Override
  899 +// public void onGetBikingRouteResult(BikingRouteResult bikingRouteResult) {
  900 +//
  901 +// }
  902 +// });
  903 + //开始检索
  904 +// routePlanSearch.drivingSearch((new DrivingRoutePlanOption())
  905 +// .from(stNode).to(enNode).policy(DrivingRoutePlanOption.DrivingPolicy.ECAR_DIS_FIRST)
  906 +// .trafficPolicy(DrivingRoutePlanOption.DrivingTrafficPolicy.ROUTE_PATH_AND_TRAFFIC));
  907 +
  908 + //开始步行检索
  909 +// routePlanSearch.walkingSearch((new WalkingRoutePlanOption())
  910 +// .from(stNode)
  911 +// .to(enNode));
  912 +// }
  913 +// showProgressDialog();
  914 +
  915 + /**
  916 + * 设置终点标记
  917 + *
  918 + * @param Latitude
  919 + * @param Longitude
  920 + */
  921 + public void markPoi(double Latitude, double Longitude) {
  922 + if (fragment.getActivity() == null) {
  923 + return;
  924 + }
  925 + baiduMap.clear();
  926 + currentMark = null;
  927 + LatLng ll = new LatLng(Latitude, Longitude);
  928 + //设置坐标
  929 + //显示当前位置图标
  930 + Bitmap pointBitmap = BitmapUtil.getBitmapFromDp(fragment.getActivity(), BitmapFactory.decodeResource(fragment.getActivity().getResources(), R.drawable.run_map_icon_end), 22, 32);
  931 + currentMark = new MarkerOptions().position(ll).icon(BitmapDescriptorFactory.fromBitmap(pointBitmap));
  932 + baiduMap.addOverlay(currentMark);
  933 + MapStatus.Builder builder = new MapStatus.Builder();
  934 + builder.target(ll).zoom(16.0f);
  935 + baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
  936 + }
  937 +
  938 + @Override
  939 + public void onSensorChanged(SensorEvent sensorEvent) {
  940 + double x = sensorEvent.values[SensorManager.DATA_X];
  941 + if (Math.abs(x - lastX) > 1.0) {
  942 + mCurrentDirection = (int) x;
  943 + if (firstLatLng != null) {
  944 + followMyLocation = new MyLocationData.Builder()
  945 + .accuracy(mCurrentAccracy)
  946 + // 此处设置开发者获取到的方向信息,顺时针0-360
  947 + .direction(mCurrentDirection).latitude(firstLatLng.latitude)
  948 + .longitude(firstLatLng.longitude).build();
  949 + baiduMap.setMyLocationData(followMyLocation);
  950 + }
  951 + }
  952 + lastX = x;
  953 + }
  954 +
  955 + @Override
  956 + public void onAccuracyChanged(Sensor sensor, int i) {
  957 +
  958 + }
  959 +
  960 + /**
  961 + * 纹理图片
  962 + *
  963 + * @return
  964 + */
  965 + public List<BitmapDescriptor> getCustomTextureList() {
  966 + ArrayList<BitmapDescriptor> list = new ArrayList<BitmapDescriptor>();
  967 + list.add(BitmapDescriptorFactory.fromAsset("Icon_road_blue_arrow.png"));
  968 +// list.add(BitmapDescriptorFactory.fromAsset("Icon_road_green_arrow.png"));
  969 +// list.add(BitmapDescriptorFactory.fromAsset("Icon_road_yellow_arrow.png"));
  970 +// list.add(BitmapDescriptorFactory.fromAsset("Icon_road_red_arrow.png"));
  971 +// list.add(BitmapDescriptorFactory.fromAsset("Icon_road_nofocus.png"));
  972 + return list;
  973 + }
  974 +
  975 + public void onResume() {
  976 + if (getContext() == null) {
  977 + return;
  978 + }
  979 + if (mMapView != null) {
  980 + mMapView.onResume();
  981 + }
  982 + //todo 防止停止后,再次开始,无法获取到赛道的轨迹
  983 + if (runRaceDetailInfo != null) {
  984 + if (runRaceDetailInfo.getFenceId() != null && !TextUtils.isEmpty(runRaceDetailInfo.getFenceId())) {
  985 + //设置围栏ID
  986 + CommonInfo.setFenceId(getContext(), Integer.parseInt(runRaceDetailInfo.getFenceId()));
  987 + }
  988 + }
  989 +
  990 + }
  991 +
  992 + public void checkStartBtnState() {
  993 + //判断是否有进行中的赛事
  994 + userStepEntity = StepUtil.getUserStepData(getContext(), CommonInfo.getUserId(getContext()));
  995 + Log.e(TAG, "checkStartBtnState: " + userStepEntity);
  996 + if (userStepEntity != null) {
  997 + //判断赛事id是否一致
  998 + String currentStreetId = CommonInfo.getStreetId(getContext());
  999 + //数据库保存的id
  1000 + String dbStreetId = userStepEntity.getStreetId();
  1001 + //获取当前时间戳
  1002 + long currnetTime = SystemClock.elapsedRealtime();
  1003 + //获取用户暂停的时间戳
  1004 + long userPauseTime = userStepEntity.getChronometerBase();
  1005 + //判断时间是否小于9小时
  1006 + Log.e(TAG, "checkStartBtnState: " + currnetTime + ",userPauseTime:" + userPauseTime);
  1007 + if ((currnetTime - userPauseTime) <= (9 * 60 * 60 * 1000)) {
  1008 + Log.e(TAG, "小于9小时");
  1009 + fragment.binding.tvRunNow.setText("继续运动");
  1010 + fragment.binding.rlScrollViewStartBtn.setTag("2");
  1011 + } else {
  1012 + Log.e(TAG, "大于9小时");
  1013 + //重置数据
  1014 + CommonInfo.resetRace(getContext());
  1015 + //清空数据库
  1016 + StepUtil.clearRunData(getContext(), CommonInfo.getUserId(getContext()));
  1017 + fragment.binding.tvRunNow.setText("立即开始");
  1018 + fragment.binding.rlScrollViewStartBtn.setTag("1");
  1019 +
  1020 + }
  1021 +
  1022 + if (currentStreetId.equals(dbStreetId)) {
  1023 + isDifferentStreet = false;
  1024 + }
  1025 + //当前id与赛事id不一样
  1026 + else {
  1027 + isDifferentStreet = true;
  1028 + }
  1029 +
  1030 + } else {
  1031 + fragment.binding.tvRunNow.setText("立即开始");
  1032 + fragment.binding.rlScrollViewStartBtn.setTag("1");
  1033 + }
  1034 + //判断赛事是否已经结束
  1035 + checkTheRaceIsEnd();
  1036 +
  1037 + }
  1038 +
  1039 + /**
  1040 + * 判断赛事是否已经结束
  1041 + */
  1042 + private void checkTheRaceIsEnd() {
  1043 + //判断赛事是否结束
  1044 + if (null != userStepEntity) {
  1045 + if (null != runRaceDetailInfo) {
  1046 + //判断赛事id是否一致
  1047 + if (!TextUtils.isEmpty(userStepEntity.getStreetId())) {
  1048 + if (userStepEntity.getStreetId().equals(CommonInfo.getStreetId(getContext()))) {
  1049 + //判断赛事是否结束
  1050 + if (runRaceDetailInfo.isEndState()) {
  1051 + //结束清除数据
  1052 + //清空上次保存数据
  1053 + StepUtil.clearRunData(getContext(), CommonInfo.getUserId(getContext()));
  1054 + //停止服务
  1055 + stopStepService();
  1056 + //清除数据
  1057 + CommonInfo.resetRace(getContext());
  1058 + //设置按钮状态
  1059 + fragment.binding.rlScrollViewStartBtn.setTag("3");
  1060 + fragment.binding.rlScrollViewStartBtn.setBackgroundColor(getContext().getResources().getColor(R.color.red_round));
  1061 + fragment.binding.tvRunNow.setText("赛事已结束");
  1062 + fragment.binding.tvGoTip.setVisibility(View.GONE);
  1063 + }
  1064 + }
  1065 + }
  1066 + }
  1067 + } else {
  1068 + //如果数据库中没有数据,即,用户在当前赛事已经结束
  1069 + if (null != runRaceDetailInfo) {
  1070 + if (runRaceDetailInfo.isEndState()) {
  1071 + //设置按钮状态
  1072 + fragment.binding.rlScrollViewStartBtn.setTag("3");
  1073 + fragment.binding.rlScrollViewStartBtn.setBackgroundColor(getContext().getResources().getColor(R.color.red_round));
  1074 + fragment.binding.tvRunNow.setText("赛事已结束");
  1075 + fragment.binding.tvGoTip.setVisibility(View.GONE);
  1076 + }
  1077 + }
  1078 + }
  1079 + }
  1080 +
  1081 + /**
  1082 + * 赛事已经结束
  1083 + */
  1084 + private void raceHasEnd() {
  1085 +
  1086 + }
  1087 +
  1088 + public void onPause() {
  1089 + if (mMapView != null) {
  1090 + mMapView.onPause();
  1091 + }
  1092 + }
  1093 +
  1094 + public void onDestroy() {
  1095 + if (mMapView != null) {
  1096 + mMapView.onDestroy();
  1097 + mMapView = null;
  1098 + }
  1099 + if (mLocClient != null) {
  1100 + mLocClient.stop();
  1101 + }
  1102 + }
  1103 +
  1104 + /**
  1105 + * //设置定位监听器,获取到用户当前位置 杨帅
  1106 + * 定位SDK监听函数
  1107 + */
  1108 + public class MyLocationListenner extends BDAbstractLocationListener {
  1109 +
  1110 + @Override
  1111 + public void onReceiveLocation(BDLocation location) {
  1112 + // map view 销毁后不在处理新接收的位置
  1113 + if (location == null || mMapView == null) {
  1114 + return;
  1115 + }
  1116 + if (isFirstLoc) {
  1117 + isFirstLoc = false;
  1118 + if (location.getRadius() > Constant.LOCA_ACCURACY) {
  1119 + Toast.makeText(getContext(), "当前定位精度为:" + location.getRadius() + "米,请您移动至空旷地带!", Toast.LENGTH_SHORT).show();
  1120 + }
  1121 +
  1122 + } else {
  1123 + //过滤定位精度
  1124 + if (location.getRadius() > Constant.LOCA_ACCURACY) {
  1125 + return;
  1126 + }
  1127 + }
  1128 + followMyLocation = new MyLocationData.Builder()
  1129 + .accuracy(location.getRadius())
  1130 + // 此处设置开发者获取到的方向信息,顺时针0-360
  1131 + .direction(location.getDirection()).latitude(location.getLatitude())
  1132 + .longitude(location.getLongitude()).build();
  1133 + if (followMyLocation == null || followMyLocation.latitude == 0 || followMyLocation.longitude == 0) {
  1134 + return;
  1135 + }
  1136 +
  1137 + MapStatus.Builder builder = new MapStatus.Builder();
  1138 + firstLatLng = new LatLng(location.getLatitude(),
  1139 + location.getLongitude());
  1140 + baiduMap.setMyLocationData(followMyLocation);
  1141 + //没有获取到轨迹
  1142 + if ((null == queryResultPoints || queryResultPoints.size() < 1) && null != firstLatLng) {
  1143 + builder.target(firstLatLng).zoom(DEFULT_ZOOM);
  1144 + baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
  1145 + }
  1146 +//
  1147 +
  1148 +// //显示当前位置图标
  1149 +// Bitmap pointBitmap = BitmapUtil.getBitmapFromDp(getContext(), BitmapFactory.decodeResource(getContext().getResources(), R.drawable.rt_ic_location), 40, 40);
  1150 +// currentMark = new MarkerOptions().position(firstLatLng).icon(BitmapDescriptorFactory.fromBitmap(pointBitmap));
  1151 +// baiduMap.addOverlay(currentMark);
  1152 +
  1153 + //根据几个关键点进行步行路径规划
  1154 +// if (importLatLngs != null) {
  1155 +// if (importLatLngs.size() >= 1) {
  1156 +// for (int index = 0; index < importLatLngs.size(); index++) {
  1157 +// //开始分段规划路径
  1158 +// //第一个点
  1159 +// if (index == 0) {
  1160 +// searchRouteResult(startLatLng, importLatLngs.get(index), 0, importLatLngs.size());
  1161 +// } else {
  1162 +// searchRouteResult(importLatLngs.get(index - 1), importLatLngs.get(index), index, importLatLngs.size());
  1163 +// }
  1164 +// }
  1165 +// } else {
  1166 +// searchRouteResult(startLatLng, endLatLng, 0, importLatLngs.size());
  1167 +// }
  1168 +// }
  1169 +
  1170 +// }
  1171 + }
  1172 + }
  1173 +
  1174 + /**
  1175 + * 显示loading
  1176 + */
  1177 + public void showLoadingView() {
  1178 + if (fragment.binding.emptyLayout == null) {
  1179 + return;
  1180 + }
  1181 + fragment.binding.emptyLayout.show(true);
  1182 + }
  1183 +
  1184 + /**
  1185 + * 隐藏loading
  1186 + */
  1187 + public void hideLoadingView() {
  1188 + if (fragment.binding.emptyLayout == null) {
  1189 + return;
  1190 + }
  1191 + fragment.binding.emptyLayout.hide();
  1192 + }
  1193 +
  1194 + /**
  1195 + * 显示重试页面
  1196 + *
  1197 + * @param errorCode
  1198 + * @param listener
  1199 + */
  1200 + public void showRetryView(int errorCode, View.OnClickListener listener) {
  1201 + if (getContext() == null) {
  1202 + return;
  1203 + }
  1204 + //隐藏地图
  1205 + fragment.binding.mapView.setVisibility(View.GONE);
  1206 + //显示空视图
  1207 + fragment.binding.emptyLayout.setVisibility(View.VISIBLE);
  1208 + //隐藏底部卡片
  1209 + fragment.binding.slidingLayout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN);
  1210 + if (fragment.binding.emptyLayout == null) return;
  1211 + String titleText = "";
  1212 + String detailText = "";
  1213 + if (errorCode == -3) {
  1214 + titleText = getContext().getString(R.string.msg_failed_network_title);
  1215 + detailText = getContext().getString(R.string.msg_failed_network_detail);
  1216 + } else {
  1217 + titleText = getContext().getString(R.string.msg_failed_other_title);
  1218 + detailText = getContext().getString(R.string.msg_failed_other_detail);
  1219 + }
  1220 + fragment.binding.emptyLayout.show(false, titleText, detailText, getContext().getString(R.string.retry), R.drawable.wufalianjie, listener);
  1221 + }
  1222 +
  1223 +
  1224 + /**
  1225 + * 启动计步服务
  1226 + */
  1227 + public void startStepService(Context context) {
  1228 + CommonInfo.setIsFirstStepSendTraceTip(getContext(), true);
  1229 + QMUITipDialogUtil.loadingDialog(getContext(), "请稍后", false);
  1230 + CommonInfo.setIsRunKeepAliveService(context, true);
  1231 + CommonInfo.setIsRunStepService(context, true);
  1232 + CommonInfo.setTsRunBaiduTraceService(context, true);
  1233 + CommonInfo.setIsWriteUserStep(context, true);
  1234 + Intent intent = new Intent(fragment.getActivity(), KeepLiveService.class);
  1235 + ContextCompat.startForegroundService(fragment.getActivity(), intent);
  1236 +
  1237 + }
  1238 +
  1239 +
  1240 + public void setRegistrationBtn() {
  1241 + if (getContext() == null) {
  1242 + return;
  1243 + }
  1244 + fragment.binding.rlScrollViewStartBtn.setTag("1");
  1245 + fragment.binding.tvRunNow.setText("现在开始");
  1246 + fragment.binding.tvGoTip.setVisibility(View.VISIBLE);
  1247 + }
  1248 +
  1249 +}
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/ui/adapter/MyRecordAdapter.java
... ... @@ -55,11 +55,8 @@ public class MyRecordAdapter extends RecyclerView.Adapter&lt;MyRecordAdapter.MyView
55 55 myViewHolder.my_record_ry.setVisibility(View.VISIBLE);
56 56 myViewHolder.has_report.setVisibility(View.GONE);
57 57 myViewHolder.my_record.setOnClickListener(v -> startAc(list.get(i)));
58   - myViewHolder.check_raking.setOnClickListener(v ->
59   - ARouter.getInstance().build("/web/WebViewColorActivity")
60   - .withString("url", AppConfig.isDebug() ? "http://wjjh5test.cnlive.com/cnSportListOver.html" : "http://wjjh5.cnlive.com/cnSportListOver.html"+"?sid="+CommonInfo.getUserId(context)+"&eventId="+list.get(i).getId())
61   - .withString("title","总排行榜")
62   - .navigation(context));
  58 + myViewHolder.check_raking.setOnClickListener(v -> toRaking(list.get(i).getId()+""));
  59 +
63 60 if (clickListener != null) {
64 61 myViewHolder.item_ly.setOnClickListener(v -> clickListener.onClickListener(list.get(i), i));
65 62 }
... ... @@ -92,6 +89,13 @@ public class MyRecordAdapter extends RecyclerView.Adapter&lt;MyRecordAdapter.MyView
92 89 RaceRecordActivity.newInstance(context,listBean.getTitle());
93 90 }
94 91  
  92 + private void toRaking(String eventId){
  93 + String baseWebUrl = AppConfig.isDebug() ? "http://wjjh5test.cnlive.com/cnSportListOver.html" : "http://wjjh5.cnlive.com/cnSportListOver.html";
  94 + ARouter.getInstance().build("/web/WebViewColorActivity")
  95 + .withString("url", baseWebUrl +"?sid="+CommonInfo.getUserId(context)+"&eventId="+eventId)
  96 + .withString("title","总排行榜")
  97 + .navigation(context);
  98 + }
95 99  
96 100 @Override
97 101 public int getItemCount() {
... ...