| | |
| | | import com.dayu.pipirrapp.utils.ToastUtil; |
| | | import com.dayu.pipirrapp.utils.WebViewUtils; |
| | | import com.dayu.pipirrapp.view.ConfirmDialog; |
| | | import com.dayu.pipirrapp.view.TipUtil; |
| | | import com.hjq.permissions.OnPermissionCallback; |
| | | import com.hjq.permissions.Permission; |
| | | import com.hjq.permissions.XXPermissions; |
| | | import com.jeremyliao.liveeventbus.LiveEventBus; |
| | | import com.tencent.bugly.crashreport.CrashReport; |
| | | |
| | |
| | | }); |
| | | //巡检按钮 |
| | | binding.inspectButton.setOnClickListener(v -> { |
| | | if (XXPermissions.isGranted(MapFragment.this.getContext(), Permission.ACCESS_BACKGROUND_LOCATION)) { |
| | | chageInspecState(InspectionUtils.STAT_INSPECTION_ONCLICK); |
| | | } else { |
| | | TipUtil.show(MapFragment.this.getActivity(), "巡检定位需要您选择\"始终允许\"定位信息,否则无法巡检。", new TipUtil.TipListener() { |
| | | @Override |
| | | public void onCancle() { |
| | | getPermissions(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | }); |
| | | //暂停巡检 |
| | | binding.inspectPause.setOnClickListener(v -> { |
| | |
| | | confirmDialog.dismiss(); |
| | | chageInspecState(InspectionUtils.NO_INSPECTION); |
| | | SharedPreferencesHelper.getInstance(MapFragment.this.getContext()).put(CommonKeyName.inspectionState, InspectionUtils.NO_INSPECTION); |
| | | //有可能还没获取到定位信息就结束巡检了 |
| | | if (lastLatLonBean != null) { |
| | | //更新本地数据库结束时间 |
| | | mInspectionBean.setStopTime(DateUtils.getNowDateStr()); |
| | | InspectionUtils.upataInspectionData(MapFragment.this.getContext(), mInspectionBean); |
| | |
| | | mWebView.evaluateJavascript("javascript:cleanLocationLay()", value -> { |
| | | }); |
| | | lastLatLonBean = null; |
| | | } |
| | | } |
| | | }); |
| | | confirmDialog.show(); |
| | |
| | | SharedPreferencesHelper.getInstance(this.getContext()).put(CommonKeyName.inspectionState, InspectionUtils.STAT_INSPECTION); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 申请后台定位权限 |
| | | */ |
| | | private void getPermissions() { |
| | | try { |
| | | XXPermissions.with(MapFragment.this.getContext()) |
| | | // 申请多个权限 |
| | | .permission(Permission.ACCESS_BACKGROUND_LOCATION) |
| | | .request(new OnPermissionCallback() { |
| | | |
| | | @Override |
| | | public void onGranted(@NonNull List<String> permissions, boolean allGranted) { |
| | | if (allGranted) { |
| | | chageInspecState(InspectionUtils.STAT_INSPECTION_ONCLICK); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onDenied(@NonNull List<String> permissions, boolean doNotAskAgain) { |
| | | if (doNotAskAgain) { |
| | | // 如果是被永久拒绝就跳转到应用权限系统设置页面 |
| | | TipUtil.show(MapFragment.this.getActivity(), "被永久拒绝授权,请手动授予定位始终允许权限!选择“权限”-->“位置信息”-->“始终允许”,然后返回应用。", new TipUtil.TipListener() { |
| | | @Override |
| | | public void onCancle() { |
| | | XXPermissions.startPermissionActivity(MapFragment.this.getContext(), permissions); |
| | | } |
| | | }); |
| | | } else { |
| | | ToastUtil.showToastLong(MapFragment.this.getContext(), "获取定位始终允许权限失败"); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } catch (Throwable e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |