diff --git a/app/libs/base-java-release.aar b/app/libs/base-java-release.aar index 562d7c8..0be8b2e 100644 Binary files a/app/libs/base-java-release.aar and b/app/libs/base-java-release.aar differ diff --git a/app/libs/coordlib-release.aar b/app/libs/coordlib-release.aar index 0a10e1c..5fa09a5 100644 Binary files a/app/libs/coordlib-release.aar and b/app/libs/coordlib-release.aar differ diff --git a/app/libs/device-ui-release.aar b/app/libs/device-ui-release.aar index 38b3387..5a31275 100644 Binary files a/app/libs/device-ui-release.aar and b/app/libs/device-ui-release.aar differ diff --git a/app/libs/totalstation-release.aar b/app/libs/totalstation-release.aar index 3af5d1f..649e83e 100644 Binary files a/app/libs/totalstation-release.aar and b/app/libs/totalstation-release.aar differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d606447..68197b2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -151,6 +151,10 @@ android:name=".ui.lofting.pointlofting.PointStakingActivity" android:exported="true" android:windowSoftInputMode="adjustResize|stateHidden" /> + - - activityIProvider) { + super(activityIProvider); + cachedCoordinateSystemKt = new CachedCurrentCoordinateSystemKt(activity); + activity.getLifecycle().addObserver(new LifecycleEventObserver() { + @Override + public void onStateChanged(@NonNull LifecycleOwner source, @NonNull Lifecycle.Event event) { + switch (event) { + case ON_CREATE: + EventBus.getDefault().register(MainActivityUtils.this); +// SoundPoolUtil.getInstance().initHintSing(activity, SoundPoolUtil.TEST, R.raw.savedone); +//// SoundPoolUtil.getInstance().initHintSing(activity, SoundPoolUtil.SEPTENTRIO_FILL, R.raw.septentrio_fill); +//// SoundPoolUtil.getInstance().initHintSing(activity, SoundPoolUtil.SEPTENTRIO_CUT, R.raw.septentrio_cut); +// SoundPoolUtil.getInstance().initHintSing(activity, SoundPoolUtil.ALPHA_STAKING, R.raw.alphastaking); +// SoundPoolUtil.getInstance().initHintSing(activity, SoundPoolUtil.ALPHA_RECORDING, R.raw.alpharecording); + break; + case ON_DESTROY: + EventBus.getDefault().unregister(MainActivityUtils.this); + SoundPoolUtil.getInstance().onDestroy(); + break; + case ON_RESUME: + checkGnssServerReady(); + break; + } + } + }); + } + + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageEvent(RtkSpeechEvent event) { + if (!StringUtils.isEmpty(event.getText())) TtsManager.getInstance().speak(event.getText()); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageEvent(RtkCheckBaseMoveEvent event) { + //检查是否需要进行基站平移校准 + String needBaseCorrect = GnssUtil.checkNeedBaseCorrect(); + if (GnssPosition.getInstance().isBaseMoveRemind() && (event.isConfirmMoved() || needBaseCorrect != null)) { + new MaterialDialog.Builder(/*this*/context()).title(R.string.hint) + .content("检测到基站位置发生变化,为了保证精度可靠,请选择基站平移校准" + (event.isConfirmMoved() ? "" : (needBaseCorrect == null ? "" : "\n(" + needBaseCorrect + ")"))) + .positiveText(R.string.rtk_base_correct) + .negativeText("忽略") + .neutralText("本次不再提醒") + .onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + Intent intent = new Intent(Utils.getApp(), RtkBaseCorrectActivity.class); + startActivity(intent); + } + }).onNeutral(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + GnssPosition.getInstance().setBaseMoveRemind(false); + } + }).show(); + } + } + + public void checkRtkLocation() { + if (Device.getInstance().deviceType != DeviceTypeEnum.DEVICE_TYPE_RTK) return; + if (((BaseApp) Utils.getApp()).avGeoPoint == null && GnssPosition.getInstance().validate) { + Blh blh = GnssPosition.getInstance().getWgs84Blh(); + if (!CUtil.isEqual(blh.getLatitude(), 0) && !CUtil.isEqual(blh.getLongitude(), 0)) { + ((BaseApp) Utils.getApp()).avGeoPoint = new LCGeoPoint(blh.getLatitude(), blh.getLongitude()); + ((BaseApp) Utils.getApp()).lastRTKLocation = ((BaseApp) Utils.getApp()).avGeoPoint.getLatitude() + "," + ((BaseApp) Utils.getApp()).avGeoPoint.getLongitude(); + Util.putPreference("lastRTKLocation", ((BaseApp) Utils.getApp()).lastRTKLocation); + } + } + if (GnssPosition.getInstance().getPosType() != GnssPosition.POS_TYPE_NONE//初始化时跳过 + && cachedCoordinateSystemKt.isDataReady() && Device.getInstance().remindCentLngUnusual//已经提示过就不再提示 + && Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_RTK//RTK时才提示 + && Math.abs(GnssPosition.getInstance().getWgs84Blh().getLongitude() - cachedCoordinateSystemKt.coordinateSystem().centLng) > 3.0d) { + if (cenLngUnusualDialog == null || !cenLngUnusualDialog.isShowing()) { + if (ActivityUtils.getTopActivity() != null && !ActivityUtils.getTopActivity().isFinishing()) + cenLngUnusualDialog = new MaterialDialog.Builder(ActivityUtils.getTopActivity()).title(R.string.hint).content(getString(R.string.center_longitude_unusual) + getString(R.string.current_center_longitude) + ":" + CoordUtil.radianToDmsDoubleString(Math.toRadians(cachedCoordinateSystemKt.coordinateSystem().centLng), 6, false)).positiveText(R.string.confirm).onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + Device.getInstance().remindCentLngUnusual = false; + Util.putPreference("remindCentLngUnusual", Device.getInstance().remindCentLngUnusual); + } + }).show(); + } + } + } + + /** + * 连接设备成功后,启动相关服务,因为Ntrip与SN无关,可以在此执行,与SN相关的服务在RtkReceivedSerialNumberEvent事件后执行 + */ + public void onDeviceConnectSuccess() { + if (deviceConnectingProgressDialog != null && deviceConnectingProgressDialog.isShowing()) { + deviceConnectingProgressDialog.dismiss(); + deviceConnectingProgressDialog = null; + } + if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_RTK) { + if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_SPP || Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_BLE) { + if (Gnss.getInstance().getDevice().getCurDataLink() == DataLinkModeEnum.PHONE) { + if (!Device.getInstance().isRtkInitDone()) { + Device.getInstance().rtkRunnableStart(); + Device.getInstance().rtkInit(); + } + if (Gnss.getInstance().getNetwork().getMode() == NetworkModeEnum.NTRIP) {//因为SDK与deviceID相关,所以在获取序列号后执行,而Ntrip启动是在连接成功后就可以 + EventBus.getDefault().post(new RtkStartNtripServiceEvent()); + ToastUtils.showShort(R.string.phone_network_diff_initialization); + } + } else { + if (!Device.getInstance().isRtkInitDone()) { + Device.getInstance().rtkRunnableStart(); + Device.getInstance().rtkInit(); + } + } + } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_QXBT) { + if (!Device.getInstance().isRtkInitDone()) { + Device.getInstance().rtkRunnableStart(); + Device.getInstance().rtkInit(); + } + } else { + //手机定位或演示模式 + } + } else { + TotalStation.getInstance().runnableStart(); + TotalStation.getInstance().init(); +// if (((App) Utils.getApp()).isShowTsSetupStationOption) chooseSetupStationType(); + } + //记录用户联机时手机定位的大概位置 + if (ActivityCompat.checkSelfPermission(/*this*/context(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { + LocationManager mLocationManager = ((LocationManager) context().getSystemService(Context.LOCATION_SERVICE)); + if (mLocationManager != null) { + List providers = mLocationManager.getProviders(true); + if (providers.contains(LocationManager.GPS_PROVIDER)) { + Location location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); + if (location != null) { + ((BaseApp) Utils.getApp()).lastPhoneLocation = location.getLatitude() + "," + location.getLongitude(); + Util.putPreference("lastPhoneLocation", ((BaseApp) Utils.getApp()).lastPhoneLocation); + } + } + } + } + } + + /** + * 获取SN号后启动与SN相关的服务 + * + * @param event + */ + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageEvent(RtkReceivedSerialNumberEvent event) {//因为SDK与deviceID相关,所以在此执行,而Ntrip启动是在连接成功后就可以 + if (Gnss.getInstance().getDevice().getCurDataLink() == DataLinkModeEnum.PHONE) { + if (Gnss.getInstance().getNetwork().getMode() == NetworkModeEnum.QXWZ_SDK) { + EventBus.getDefault().post(new RtkStartQxwzSdkServiceEvent()); + ToastUtils.showShort(R.string.qxwz_service_initialization); + } else if (Gnss.getInstance().getNetwork().getMode() == NetworkModeEnum.CMCC_SDK) { + EventBus.getDefault().post(new RtkStartCmccServiceEvent()); + ToastUtils.showShort(R.string.cmcc_service_initialization); + } else if (Gnss.getInstance().getNetwork().getMode() == NetworkModeEnum.SIXENTS_SDK) { + EventBus.getDefault().post(new RtkStartSixentsServiceEvent()); + ToastUtils.showShort(R.string.sixents_service_initialization); + } else if (Gnss.getInstance().getNetwork().getMode() == NetworkModeEnum.LUOWANG_SDK) { + EventBus.getDefault().post(new RtkStartLuoWangServiceEvent()); + ToastUtils.showShort(R.string.luowang_service_initialization); + } + } + } + + public void onDeviceConnectFailed() { + if (deviceConnectingProgressDialog != null && deviceConnectingProgressDialog.isShowing()) { + deviceConnectingProgressDialog.dismiss(); + deviceConnectingProgressDialog = null; + ToastUtils.showShort(R.string.device_connect_failed); + } + } + + public void onDeviceConnectLost() { + ToastUtils.showShort(R.string.device_connect_lost); + } + + public void onRequestConnect() { + if (deviceConnectingProgressDialog == null || !deviceConnectingProgressDialog.isShowing()) { + deviceConnectingProgressDialog = new BCProgressDialog.Builder(ActivityUtils.getTopActivity()).title(R.string.connect_device).build(); + deviceConnectingProgressDialog.show(); + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageEvent(TsUpdateStatusEvent event) { +// Fragment currentFragment = MainFragmentUtil.getCurrentFragment(/*this*/activity(), MainActivity.mainContainer); +// if (currentFragment instanceof TcsAutoScan2DxfFragment) { +// ((TcsAutoScan2DxfFragment) currentFragment).updateStatus(event.getStatus()); +// } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageEvent(RtkStartNtripServiceEvent event) { +// CorsUseLogManager.getInstance().logEvent("MainActivity-onMessageEvent-StartNtripServiceEvent"); + ServiceUtils.startService(NtripService.class); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageEvent(RtkStartQxwzSdkServiceEvent event) { +// CorsUseLogManager.getInstance().logEvent("MainActivity-onMessageEvent-StartQxwzServiceEvent"); + ServiceUtils.startService(QxwzSdkService.class); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageEvent(RtkStartSixentsServiceEvent event) { +// CorsUseLogManager.getInstance().logEvent("MainActivity-onMessageEvent-StartSixentsServiceEvent"); + ServiceUtils.startService(SixentsSdkService.class); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageEvent(RtkStartCmccServiceEvent event) { +// CorsUseLogManager.getInstance().logEvent("MainActivity-onMessageEvent-StartCmccServiceEvent"); + ServiceUtils.startService(CmccSdkService.class); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageEvent(RtkStartLuoWangServiceEvent event) { +// CorsUseLogManager.getInstance().logEvent("MainActivity-onMessageEvent-StartLuoWangServiceEvent"); + ServiceUtils.startService(LuoWangSdkService.class); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageEvent(RtkStopNtripSDKEvent event) { + ServiceUtils.stopService(NtripService.class); + ServiceUtils.stopService(QxwzSdkService.class); + ServiceUtils.stopService(CmccSdkService.class); + ServiceUtils.stopService(LuoWangSdkService.class); + ServiceUtils.stopService(SixentsSdkService.class); + Device.getInstance().oneKeyFixValid = false; + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageEvent(RtkCmdAnswerEvent event) { + Device.getInstance().rtkProcessCmdAnswer(event.getSentence()); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageEvent(RtkCmdQueueSendEvent event) { + Device.getInstance().rtkSendCommand(event.getQueue()); + } + + @Subscribe(threadMode = ThreadMode.MAIN) + public void onMessageEvent(RtkCmdUiEvent event) { + if (event.getContent() == null) { + Device.getInstance().rtkUpdateUiMessage(event.getWhat()); + } else { + Device.getInstance().rtkUpdateUiMessage(event.getWhat(), event.getContent()); + } + } + +// /** +// * 选择设站模式 +// */ +// private void chooseSetupStationType() { +// if (((App) Utils.getApp()).lastTsSetupStationType < 0 || ((App) Utils.getApp()).lastTsSetupStationType > 4) +// ((App) Utils.getApp()).lastTsSetupStationType = 0; +// new MaterialDialog.Builder(ActivityUtils.getTopActivity()) +// .title(R.string.total_station_setup_type) +// .items(R.array.setup_station_type_with_current) +// .itemsCallbackSingleChoice(((App) Utils.getApp()).lastTsSetupStationType, new MaterialDialog.ListCallbackSingleChoice() { +// @Override +// public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) { +// switch (which) { +// case 0: +// startActivity(new Intent(Utils.getApp(), SetupStationCurrentActivity.class)); +// break; +// case 1: +// TsConfig.getInstance().setSetupStationMethod(SetupStationMethodEnum.TS_DONE_SKIP); +// ToastUtils.showShort(R.string.apply_success); +// break; +// case 2: +// TsConfig.getInstance().setSetupStationMethod(SetupStationMethodEnum.TS_DONE_INPUT_INTO_APP); +// startActivity(new Intent(Utils.getApp(), SetupStationInputActivity.class)); +// break; +// case 3: +// TsConfig.getInstance().setSetupStationMethod(SetupStationMethodEnum.APP_SETUP_KNOWN_BACK_SIGHT); +// startActivity(new Intent(Utils.getApp(), SetupStationKnownBackSightActivity.class)); +// break; +// case 4: +// TsConfig.getInstance().setSetupStationMethod(SetupStationMethodEnum.APP_SETUP_RESECTION); +// startActivity(new Intent(Utils.getApp(), SetupStationResectionActivity.class)); +// break; +// } +// TsConfig.getInstance().save(); +// ((App) Utils.getApp()).lastTsSetupStationType = which; +// Util.putPreference("lastTsSetupStationType", ((App) Utils.getApp()).lastTsSetupStationType); +// return false; +// } +// }).positiveText(R.string.next) +// .neutralText(R.string.not_show_again) +// .onNeutral(new MaterialDialog.SingleButtonCallback() { +// @Override +// public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { +// Util.putPreference("key_is_show_ts_setup_station_option", false); +// ((App) Utils.getApp()).isShowTsSetupStationOption = false; +// new MaterialDialog.Builder(ActivityUtils.getTopActivity()) +// .content(R.string.set_show_ts_setup_station_option_in_setting) +// .positiveText(R.string.i_know) +// .show(); +// } +// }).show(); +// } + + /** + * 连接蓝牙先请求打开定位权限 + */ + public void requestBluetoothPermission() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && XXPermissions.isGranted(ActivityUtils.getTopActivity(), Permission.BLUETOOTH_CONNECT)) {//S及以后不需要位置权限 + checkConnectLast(); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {//S及以后不需要位置权限,此时只需请求connect权限 + if (XXPermissions.isGranted(ActivityUtils.getTopActivity(), Permission.BLUETOOTH_CONNECT)) { + checkConnectLast(); + } else { + new MaterialDialog.Builder(ActivityUtils.getTopActivity()) + .title(R.string.location_permission) + .content(R.string.bluetooth_need_location_permission) + .canceledOnTouchOutside(false) + .positiveText(R.string.to_allow) + .negativeText(R.string.refuse) + .onPositive((dialog, which) -> { + XXPermissions.with(ActivityUtils.getTopActivity()) + .permission(Permission.BLUETOOTH_CONNECT) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + checkConnectLast(); + } + + @Override + public void onDenied(List permissions, boolean never) { + if (never) { + ToastUtils.showLong(R.string.bluetooth_connect_need_permission); + XXPermissions.startPermissionActivity(ActivityUtils.getTopActivity(), permissions, new OnPermissionPageCallback() { + @Override + public void onGranted() { + requestBluetoothPermission(); + } + + @Override + public void onDenied() { + ToastUtils.showLong(R.string.bluetooth_connect_need_permission); + } + }); + } else { + requestBluetoothPermission(); + } + } + }); + }) + .onNegative((dialog, which) -> { + + }).show(); + } + } else {//S以下,需要请求两个权限,位置和Connect权限 + if (XXPermissions.isGranted(ActivityUtils.getTopActivity(), Permission.ACCESS_FINE_LOCATION, Permission.BLUETOOTH_CONNECT)) { + checkConnectLast(); + } else { + new MaterialDialog.Builder(ActivityUtils.getTopActivity()) + .title(R.string.location_permission) + .content(R.string.bluetooth_need_location_permission) + .canceledOnTouchOutside(false) + .positiveText(R.string.to_allow) + .negativeText(R.string.refuse) + .onPositive((dialog, which) -> { + XXPermissions.with(ActivityUtils.getTopActivity()) + .permission(Permission.ACCESS_FINE_LOCATION, Permission.BLUETOOTH_CONNECT) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + if (all) { + checkConnectLast(); + } else { + requestBluetoothPermission(); + } + } + + @Override + public void onDenied(List permissions, boolean never) { + if (never) { + ToastUtils.showLong(R.string.bluetooth_connection_requires_positioning_permission_please_turn_it_on_manually); + XXPermissions.startPermissionActivity(ActivityUtils.getTopActivity(), permissions, new OnPermissionPageCallback() { + @Override + public void onGranted() { + requestBluetoothPermission(); + } + + @Override + public void onDenied() { + ToastUtils.showLong(R.string.bluetooth_connect_need_permission); + } + }); + } else { + requestBluetoothPermission(); + } + } + }); + }) + .onNegative((dialog, which) -> { + + }).show(); + } + } + } + + /** + * 检查权限 + */ + public void requestPhonePermission() { + if (!XXPermissions.isGranted(ActivityUtils.getTopActivity(), Permission.READ_PHONE_STATE)) { + long lastReadPhoneStateDeniedTime = Util.getLongPreference("lastReadPhoneStateDeniedTime", 0L); + if (System.currentTimeMillis() - lastReadPhoneStateDeniedTime > 48 * 60 * 60 * 1000L) {//每48小时提示一次 + new MaterialDialog.Builder(ActivityUtils.getTopActivity()) + .title(R.string.mobile_phone_permissions) + .content(R.string.verify_imei_imsi_code_to_prevent_account_theft) + .canceledOnTouchOutside(false) + .positiveText(R.string.to_allow) + .negativeText(R.string.refuse) + .onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + XXPermissions.with(ActivityUtils.getTopActivity()) + .permission(Permission.READ_PHONE_STATE) + .request(new OnPermissionCallback() { + @Override + public void onGranted(List permissions, boolean all) { + } + + @Override + public void onDenied(List permissions, boolean never) { + if (never) { + ToastUtils.showShort(R.string.manually_enable_the_phone_state_permission_to_bind_hardware_devices); + } + Util.putPreference("lastReadPhoneStateDeniedTime", System.currentTimeMillis()); + } + }); + } + }) + .onNegative(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + Util.putPreference("lastReadPhoneStateDeniedTime", System.currentTimeMillis()); + } + }).show(); + } + } + } + + public void showRemindConnectDeviceDialog() { + new MaterialDialog.Builder(ActivityUtils.getTopActivity()) + .title(R.string.hint) + .content(R.string.no_instrument_connected) + .positiveText(R.string.connect) + .onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + requestBluetoothPermission(); + } + }) + .negativeText(R.string.cancel) + .show(); + } + + + public void checkConnectLast() { + if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_SPP) { + if (!ServiceUtils.isServiceRunning(BTService.class.getName()) && XXPermissions.isGranted(activity(), Permission.BLUETOOTH_CONNECT)) { + ServiceUtils.startService(BTService.class); + } + } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_BLE) { + if (!ServiceUtils.isServiceRunning(BleService.class.getName()) && XXPermissions.isGranted(activity(), Permission.BLUETOOTH_CONNECT)) { + ServiceUtils.startService(BleService.class); + } + } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_QXBT) { + //千寻RTK需要GnssServer连接蓝牙 + } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_HOTSPOT) { + if (!ServiceUtils.isServiceRunning(TsSocketService.class.getName())) { + ServiceUtils.startService(TsSocketService.class); + } + } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_OTG) { + if (!ServiceUtils.isServiceRunning(OTGCommService.class.getName())) { + ServiceUtils.startService(OTGCommService.class); + } + } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_TPCOM) { + if (!ServiceUtils.isServiceRunning(TsSocketService.class.getName())) { + ServiceUtils.startService(TsSocketService.class); + } + } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_PHONE_LOCATION) { + if (!ServiceUtils.isServiceRunning(NativePositioningService.class.getName())) { + ServiceUtils.startService(NativePositioningService.class); + ThreadPoolUtil.execute(() -> Device.getInstance().requestConnect(), 500); + } + } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_EMULATOR) { + if (!ServiceUtils.isServiceRunning(EmulatorService.class.getName())) { + ServiceUtils.startService(EmulatorService.class); + } + } + if (!Device.getInstance().isDeviceConnected()) { + if (!"".equals(Device.getInstance().deviceBlueName)) { + String instrumentInfo = ActivityUtils.getTopActivity().getString(R.string.instrument_name) + ":" + Device.getInstance().deviceBlueName + "\n" + ActivityUtils.getTopActivity().getString(R.string.instrument_type_name) + ":" + Device.getInstance().deviceBrand; + new MaterialDialog.Builder(ActivityUtils.getTopActivity()) + .title(R.string.quick_connect) + .content(instrumentInfo) + .positiveText(Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS ? R.string.connect_and_setup_station : R.string.connect) + .negativeText(R.string.config) + .neutralText(R.string.switch_instrument) + .onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_HOTSPOT) { + startHotspotComm(); + } else { + if (DeviceUtil.checkIfNeedGnssServer()) { + if (DeviceUtil.checkIfGnssServerReady(ActivityUtils.getTopActivity())) {//先检查如果是千寻rtk,是否安装并打开了GnssServier + gnssServerReady = true; + } + } else { + Device.getInstance().requestConnect(); + ToastUtils.showShort(R.string.connecting_please_wait); + } + } + } + }).onNegative(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + Intent intent; + if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS) { + intent = new Intent(ActivityUtils.getTopActivity(), ConnectTSActivity.class); + } else { + intent = new Intent(ActivityUtils.getTopActivity(), ConnectRtkActivity.class); + } + intent.putExtra("customChannel", AppChannel.customChannel); + ActivityUtils.getTopActivity().startActivity(intent); + } + }).onNeutral(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + chooseInstrumentType(); + } + }).show(); + } else { + chooseInstrumentType(); + } + } else { + if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_PHONE_LOCATION) { + ToastUtils.showShort(R.string.native_rtk_is_running); + } else { + Intent intent; + if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS) { + intent = new Intent(ActivityUtils.getTopActivity(), ConnectTSActivity.class); + } else { + intent = new Intent(ActivityUtils.getTopActivity(), ConnectRtkActivity.class); + } + intent.putExtra("customChannel", AppChannel.customChannel); + ActivityUtils.getTopActivity().startActivity(intent); + } + } + + } + + public void checkGnssServerReady() { + if (gnssServerReady) { + new MaterialDialog.Builder(ActivityUtils.getTopActivity()) + .title(R.string.hint) + .content(R.string.you_need_start_gnss_server_for_communication) + .positiveText(R.string.started).onPositive(new MaterialDialog.SingleButtonCallback() { + @Override + public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + if (RTK.getInstance() instanceof QxwzRTK) { + Device.getInstance().connectType = ConnectTypeEnum.CONNECT_TYPE_QXBT; + ServiceUtils.startService(QxwzMessengerService.class); + } + } + }).negativeText(R.string.cancel).dismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + gnssServerReady = false; + } + }).show(); + } + } + + private void chooseInstrumentType() { + new MaterialDialog.Builder(ActivityUtils.getTopActivity()) + .title(R.string.choose_instrument_type) + .items(new String[]{ActivityUtils.getTopActivity().getString(R.string.total_station), ActivityUtils.getTopActivity().getString(R.string.rtk)}) + .itemsCallback(new MaterialDialog.ListCallback() { + @Override + public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) { + switch (which) { + case 0: + ConnectTSActivity.start(); + break; + case 1: + ConnectRtkActivity.start(); + break; + } + } + }).show(); + } + + + /** + * 开启wifi通信 + */ + private void startHotspotComm() { + if (!ValidateUtil.isIPAddress(TsConfig.getInstance().getIp())) { + ToastUtils.showShort(R.string.please_input_correct_ip); + return; + } + if (TsConfig.getInstance().getPort() < 1024 || TsConfig.getInstance().getPort() > 65535) { + ToastUtils.showShort(R.string.please_input_correct_port); + return; + } + if (DeviceUtil.isWifiApOpen()) { + ServiceUtils.stopService(EmulatorService.class); + ServiceUtils.stopService(LocationService.class); + ServiceUtils.stopService(NativePositioningService.class); + ServiceUtils.stopService(BTService.class); + ServiceUtils.stopService(BleService.class); + ServiceUtils.startService(TsSocketService.class); + ThreadPoolUtil.execute(new Runnable() { + @Override + public void run() { + Device.getInstance().requestConnect(); + } + }, 200); + } else { + ToastUtils.showShort(R.string.please_open_hotspot_first); + //打开网络共享与热点设置页面 + if (RomUtil.isOppo() || RomUtil.isLenove() || RomUtil.isGionee()) { + //OPPO系统系统特殊,会让在Manifest.xml声明Settings$TetherSettingsActivity,现在让用户自己找热点界面,并开启 + ToastUtils.showShort(R.string.find_tether_setting_and_open); + ActivityUtils.getTopActivity().startActivity(new Intent(Settings.ACTION_SETTINGS)); + } else { + Intent intent = new Intent(); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + ComponentName comp = new ComponentName("com.android.settings", "com.android.settings.Settings$TetherSettingsActivity"); + intent.setComponent(comp); + ActivityUtils.getTopActivity().startActivity(intent); + } + } + } +} diff --git a/app/src/main/java/com/project/survey/ui/SplashActivity.kt b/app/src/main/java/com/project/survey/ui/SplashActivity.kt index 1d66284..9dea6cf 100644 --- a/app/src/main/java/com/project/survey/ui/SplashActivity.kt +++ b/app/src/main/java/com/project/survey/ui/SplashActivity.kt @@ -10,6 +10,7 @@ import com.project.survey.model.ProjectBean import com.project.survey.ui.base.BaseBindingActivity import com.project.survey.ui.login.LoginActivity import com.project.survey.ui.project.ProjectListActivity +import com.project.survey.util.MockUtil import com.project.survey.util.SPUtils /** @@ -26,24 +27,21 @@ class SplashActivity : BaseBindingActivity() { } override fun initData() { - if (SPUtils.getString(SPConstants.TOKEN).isNullOrBlank()) { - LoginActivity.start() + if (MockUtil.isTest){ + MockUtil.login() + MainActivity.start() } else { - val currentProject = - SPUtils.getParcelable(SPConstants.CURRENT_PROJECT, ProjectBean::class.java) -// SPUtils.getParcelable(SPConstants.CURRENT_PROJECT, ProjectBean::class.java) -// ?.let { project -> -// viewModel.repo.currentProject.postValue(project) -// MainActivity.start() -// } ?: { -// //未选择工程 -// ProjectListActivity.start() -// } - if (currentProject == null) { - //未选择工程 - ProjectListActivity.start() + if (SPUtils.getString(SPConstants.TOKEN).isNullOrBlank()) { + LoginActivity.start() } else { - MainActivity.start() + val currentProject = + SPUtils.getParcelable(SPConstants.CURRENT_PROJECT, ProjectBean::class.java) + if (currentProject == null) { + //未选择工程 + ProjectListActivity.start() + } else { + MainActivity.start() + } } } finish() diff --git a/app/src/main/java/com/project/survey/ui/base/BaseBindingActivity.kt b/app/src/main/java/com/project/survey/ui/base/BaseBindingActivity.kt index fe49f57..54490c5 100644 --- a/app/src/main/java/com/project/survey/ui/base/BaseBindingActivity.kt +++ b/app/src/main/java/com/project/survey/ui/base/BaseBindingActivity.kt @@ -8,8 +8,21 @@ import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.widget.Toolbar import androidx.viewbinding.ViewBinding +import blankj.utilcode.util.LogUtils +import com.bingce.coordlib.model.Blh +import com.bingce.coordlib.model.Coordinate +import com.bingce.device.Device +import com.bingce.device.ui.manager.DeviceConnectManager +import com.bingce.device.ui.manager.RtkManager +import com.bingce.device.ui.manager.TsAnglesRefreshManager +import com.bingce.device.ui.manager.TsBatteryRefreshManager +import com.bingce.device.ui.manager.TsChangeHrManager +import com.bingce.device.ui.manager.TsMeasCoordinateManager +import com.bingce.device.ui.manager.TsMeasSdAnglesManager +import com.bingce.totalstation.TsListener import com.gyf.immersionbar.ImmersionBar import com.project.survey.R +import com.project.survey.ui.MainActivityUtils import com.project.survey.widget.LoadingDialog import org.polaric.colorful.Colorful @@ -26,6 +39,105 @@ abstract class BaseBindingActivity : AppCompatActivity() { abstract fun initData() abstract fun initListener() + protected val deviceConnectManager: DeviceConnectManager = DeviceConnectManager(this, object : Device.IDeviceConnectListener{ + override fun onDeviceConnectSucceed() { + LogUtils.d("onDeviceConnectSucceed") + } + + override fun onDeviceConnectLost() { + LogUtils.d("onDeviceConnectLost") + } + + override fun onDeviceConnectFailed() { + LogUtils.d("onDeviceConnectFailed") + } + + override fun onDeviceConnectNeedOpenBT() { + LogUtils.d("onDeviceConnectNeedOpenBT") + } + + }) + protected val rtkManager: RtkManager = RtkManager(this, object : RtkManager.IRtkListener { + override fun onRtkPositionReceived( + p0: Double, + p1: Blh?, + p2: Blh?, + p3: Coordinate?, + p4: Double, + p5: Double, + p6: Double + ) { + LogUtils.d("onRtkPositionReceived:${p0};${p1};${p2};${p3};${p4};${p5};${p6};") + } + + override fun onRtkStatusChanged() { + LogUtils.d("onRtkStatusChanged") + } + + override fun onRtkError(p0: String?) { + LogUtils.d("onRtkError:${p0}") + } + + override fun onRtkPoleHeightChanged() { + LogUtils.d("onRtkPoleHeightChanged") + } + + override fun onRtkTiltSwitched(p0: Boolean) { + LogUtils.d("onRtkTiltSwitched:${p0}") + } + + override fun onSatelliteSkyViewRefresh() { + LogUtils.d("onSatelliteSkyViewRefresh") + } + + }) + protected val tsMeasCoordinateManager: TsMeasCoordinateManager = + TsMeasCoordinateManager(this, object : TsListener.MeasCoordinateListener{ + override fun onMeasCoordinateSuccess(p0: Coordinate?) { + LogUtils.d("onMeasCoordinateSuccess:${p0}") + } + + override fun onMeasCoordinateFailed(p0: String?, p1: String?) { + LogUtils.d("onMeasCoordinateFailed:${p0};${p1}") + } + }) + protected val tsMeasSdAnglesManager: TsMeasSdAnglesManager = TsMeasSdAnglesManager(this, object : TsListener.MeasSdAnglesListener{ + override fun onMeasSdAnglesSuccess( + p0: Double, + p1: Double, + p2: Double, + p3: Double, + p4: Double, + p5: Double, + p6: Double + ) { + LogUtils.d("onMeasSdAnglesSuccess:${p0};${p1};${p2};${p3};${p4};${p5};${p6}") + } + + override fun onMeasSdAnglesFailed(p0: String?, p1: String?) { + LogUtils.d("onMeasSdAnglesFailed:${p0};${p1}") + } + }) + protected val tsAnglesRefreshManager: TsAnglesRefreshManager = + TsAnglesRefreshManager(this, object : TsListener.AnglesRefreshListener{ + override fun onAnglesRefresh(p0: Double, p1: Double) { + LogUtils.d("onAnglesRefresh:${p0};${p1}") + } + }) + protected val tsBatteryRefreshManager: TsBatteryRefreshManager = + TsBatteryRefreshManager(this) { } + protected val tsChangeHrManager: TsChangeHrManager = TsChangeHrManager(this, object : TsListener.ChangeHrListener{ + override fun onChangeHrSuccess(p0: Double) { + LogUtils.d("onChangeHrSuccess:${p0}") + } + + override fun onChangeHrFailed(p0: String?) { + LogUtils.d("onChangeHrSuccess:${p0}") + } + + }) + val mainActivityUtils: MainActivityUtils = MainActivityUtils(this) { this } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) _binding = getBinding() diff --git a/app/src/main/java/com/project/survey/ui/home/InstrumentFragment.kt b/app/src/main/java/com/project/survey/ui/home/InstrumentFragment.kt index a8e6ad5..9dcfc5b 100644 --- a/app/src/main/java/com/project/survey/ui/home/InstrumentFragment.kt +++ b/app/src/main/java/com/project/survey/ui/home/InstrumentFragment.kt @@ -8,6 +8,8 @@ import blankj.utilcode.util.AppUtils import com.bingce.device.Device import com.bingce.device.enums.ConnectTypeEnum import com.bingce.device.enums.DeviceTypeEnum +import com.bingce.device.ui.ConnectRtkActivity +import com.bingce.device.ui.ConnectTSActivity import com.bingce.rtk.command.RTK import com.bingce.rtk.config.GnssConfigManager import com.project.survey.R @@ -23,10 +25,8 @@ import com.project.survey.ui.instrument.basestationtranslation.RtkBaseCorrectAct import com.project.survey.ui.instrument.coordinatesystem.BingCeCoordinateSystemActivity import com.project.survey.ui.instrument.mobilestationmode.GnssConfigSetActivity import com.project.survey.ui.instrument.mobilestationmode.base.RtkPointCorrectActivity -import com.project.survey.ui.instrument.rtk.ConnectRtkActivity import com.project.survey.ui.instrument.satellitosis.SatelliteStatusActivity import com.project.survey.ui.instrument.setupstation.InstrumentSetFragmentSetupStationTypeUtils -import com.project.survey.ui.instrument.totalstation.ConnectTSActivity import com.project.survey.util.ActivityNavUtil import com.project.survey.util.SPUtils diff --git a/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/fragment/CoordinateSystemContainerFragment.java b/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/fragment/CoordinateSystemContainerFragment.java index 06a257a..8743a64 100644 --- a/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/fragment/CoordinateSystemContainerFragment.java +++ b/app/src/main/java/com/project/survey/ui/instrument/coordinatesystem/fragment/CoordinateSystemContainerFragment.java @@ -22,7 +22,10 @@ import androidx.viewpager.widget.ViewPager; import com.afollestad.materialdialogs.MaterialDialog; import com.bingce.coordlib.model.CoordinateSystem; import com.bingce.coordlib.util.CoordinateSystemUtil; +import com.bingce.data.base.user.UserConfig; +import com.bingce.data.base.user.UserConfigDao; import com.bingce.data.cache.AbstractCachedObserver; +import com.bingce.data.database.AppDataBase; import com.bingce.data.database.CoordinateSystemDb; import com.bingce.data.database.DBQueryConstant; import com.bingce.data.database.KeyValueDb; @@ -53,8 +56,10 @@ import com.bingce.utils.SoftKeyUtils; import com.bingce.utils.ThreadPoolUtil; import com.bingce.utils.ValidateUtil; import com.flyco.tablayout.SlidingTabLayout; +import com.project.survey.constants.SPConstants; import com.project.survey.ui.instrument.coordinatesystem.CachedCurrentCoordinateSystem; import com.project.survey.ui.instrument.mobilestationmode.base.RtkPointCorrectActivity; +import com.project.survey.util.SPUtils; import com.rengwuxian.materialedittext.MaterialEditText; import org.greenrobot.eventbus.EventBus; @@ -217,7 +222,8 @@ public class CoordinateSystemContainerFragment extends AbstractCoordinateSystemC return; } currentProjectRecord.coordinateSystem = coordinateSystem; - ProjectDb.getInstance().save(currentProjectRecord); + UserConfig userConfig = AppDataBase.getInstance().userConfigDao().findByLeanCloudUserId(SPUtils.INSTANCE.getString(SPConstants.PERSON_ID)); + ProjectDb.getInstance().userSafe(userConfig).save(currentProjectRecord); //切换线路 ThreadPoolUtil.executeInMain(success); }); diff --git a/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/RtkPointCorrectActivity.java b/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/RtkPointCorrectActivity.java index c93eb1b..1af7850 100644 --- a/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/RtkPointCorrectActivity.java +++ b/app/src/main/java/com/project/survey/ui/instrument/mobilestationmode/base/RtkPointCorrectActivity.java @@ -59,6 +59,7 @@ public class RtkPointCorrectActivity extends AbstractRtkPointCorrectActivity { @Override protected void skip2ProjViewAndModifyCurrentCoordinateSystem() { + // 点击提示弹框的“去配置”按钮 BingCeCoordinateSystemActivity.skip2ProjViewAndModifyCurrentCoordinateSystem(this); } diff --git a/app/src/main/java/com/project/survey/ui/instrument/rtk/ConnectRtkActivity.java b/app/src/main/java/com/project/survey/ui/instrument/rtk/ConnectRtkActivity.java deleted file mode 100644 index 154ec3b..0000000 --- a/app/src/main/java/com/project/survey/ui/instrument/rtk/ConnectRtkActivity.java +++ /dev/null @@ -1,1085 +0,0 @@ -package com.project.survey.ui.instrument.rtk; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.app.AlertDialog; -import android.bluetooth.BluetoothAdapter; -import android.bluetooth.BluetoothDevice; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.SharedPreferences; -import android.os.Build; -import android.os.Bundle; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.ListView; -import android.widget.Spinner; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.appcompat.widget.Toolbar; -import androidx.fragment.app.Fragment; -import androidx.preference.PreferenceManager; - -import com.afollestad.materialdialogs.DialogAction; -import com.afollestad.materialdialogs.MaterialDialog; -import com.bingce.AppChannel; -import com.bingce.coordlib.model.Coordinate; -import com.bingce.coordlib.util.CoordUtil; -import com.bingce.device.Device; -import com.bingce.device.enums.ConnectTypeEnum; -import com.bingce.device.enums.DeviceTypeEnum; -import com.bingce.device.service.comm.ble.BleService; -import com.bingce.device.service.comm.emulator.EmulatorService; -import com.bingce.device.service.comm.localgps.LocationService; -import com.bingce.device.service.comm.localgps.NativePositioningService; -import com.bingce.device.service.comm.messenger.QxwzMessengerService; -import com.bingce.device.service.comm.socket.TsSocketService; -import com.bingce.device.service.comm.spp.BTService; -import com.bingce.device.ui.ToolCommDebugActivity; -import com.bingce.device.ui.utils.DeviceUtil; -import com.bingce.event.SingleMessageEvent; -import com.bingce.rtk.command.RTK; -import com.bingce.rtk.command.qxwz.QxwzRTK; -import com.bingce.rtk.enums.RTKEnum; -import com.bingce.rtk.event.RtkCmdSendOverEvent; -import com.bingce.rtk.gnss.Gnss; -import com.bingce.rtk.model.GnssPosition; -import com.bingce.rtk.util.RtkUtil; -import com.bingce.totalstation.TotalStation; -import com.bingce.utils.AppUtil; -import com.bingce.utils.ClipboardUtils; -import com.bingce.utils.ThreadPoolUtil; -import com.bingce.utils.Util; -import com.hjq.permissions.OnPermissionCallback; -import com.hjq.permissions.Permission; -import com.hjq.permissions.XXPermissions; -import com.leon.lib.settingview.LSettingItem; -import com.project.survey.R; - -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; -import org.polaric.colorful.ColorfulActivity; - -import java.lang.reflect.Method; -import java.util.List; -import java.util.Set; - -import blankj.utilcode.util.ActivityUtils; -import blankj.utilcode.util.AppUtils; -import blankj.utilcode.util.ServiceUtils; -import blankj.utilcode.util.ToastUtils; -import blankj.utilcode.util.Utils; -import clj.fastble.BleManager; -import clj.fastble.callback.BleScanCallback; -import clj.fastble.data.BleDevice; -import clj.fastble.data.BleScanState; -import clj.fastble.scan.BleScanner; -import device.ui.Rid; -import device.ui.Rmenu; -import device.ui.Rstring; - -public class ConnectRtkActivity extends ColorfulActivity { - private static final int RC_LOCATION_PERM_SCAN = 128; - private static final int RC_LOCATION_PERM_CONNECT = 129; - private static final int RC_BLUETOOTH_PERM_SCAN = 130; - private static final int RC_BLUETOOTH_PERM_CONNECT = 131; - private static final int REQUEST_ENABLE_BT = 3; - private int currentRequestCode = -1; - private BluetoothAdapter mBtAdapter; - private ArrayAdapter mPairedDevicesArrayAdapter; - private ArrayAdapter mNewDevicesArrayAdapter; - private Toolbar mToolbar; - private LinearLayout layoutPairedDevices; - private LinearLayout layoutNewDevices; - private LinearLayout layoutEmulator; - private Spinner mSpinner1, mSpinner2; - private ListView mPairedListView; - private ListView mNewDevicesListView; - private Button mBtnConnect; - private PublicReceiver publicReceiver; - private TextView mTextViewOneKeyFixAds; - private TextView mTextViewTitleRtkType; - private LSettingItem item_starting_latitude, item_starting_longitude, item_starting_altitude, item_switch_random_direction, item_starting_direction, item_move_speed; - private boolean gnssServerReady = false; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_connect_rtk); - mToolbar = findViewById(Rid.toolbar()); - layoutPairedDevices = findViewById(Rid.activity_connect_rtk_layout_paired_devices()); - layoutNewDevices = findViewById(Rid.activity_connect_rtk_layout_new_devices()); - layoutEmulator = findViewById(Rid.activity_connect_rtk_layout_emulator()); - mSpinner1 = findViewById(Rid.activity_connect_rtk_spinner_connection_type()); - mSpinner2 = findViewById(Rid.activity_connect_rtk_spinner_rtk_type()); - mPairedListView = findViewById(Rid.activity_connect_rtk_paired_devices()); - mNewDevicesListView = findViewById(Rid.activity_connect_rtk_new_devices()); - mBtnConnect = findViewById(Rid.activity_connect_rtk_btn_connect()); - mTextViewOneKeyFixAds = findViewById(Rid.activity_connect_rtk_tv_one_key_fix_ads()); - mTextViewTitleRtkType = findViewById(Rid.activity_connect_rtk_title_rtk_type()); - item_starting_latitude = findViewById(Rid.activity_connect_rtk_layout_emulator_start_latitude()); - item_starting_longitude = findViewById(Rid.activity_connect_rtk_layout_emulator_start_longitude()); - item_starting_altitude = findViewById(Rid.activity_connect_rtk_layout_emulator_start_altitude()); - item_switch_random_direction = findViewById(Rid.activity_connect_rtk_layout_emulator_switch_random_direction()); - item_starting_direction = findViewById(Rid.activity_connect_rtk_layout_emulator_start_direction()); - item_move_speed = findViewById(Rid.activity_connect_rtk_layout_emulator_speed()); - - setSupportActionBar(mToolbar); - if (getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); - EventBus.getDefault().register(this); - -// boolean fromOneKeyFix = getIntent().getBooleanExtra("fromOneKeyFix", false); -// if (fromOneKeyFix -// || AppChannel.customChannel == AppChannel.CUSTOM_FJD -// || AppChannel.customChannel == AppChannel.CUSTOM_COMNAV -// || AppChannel.customChannel == AppChannel.CUSTOM_SURVEY_SPACE -// || AppChannel.customChannel == AppChannel.CUSTOM_SURVEY_SPACE_INTERNATIONAL) - mTextViewOneKeyFixAds.setVisibility(View.GONE); - - //当存在公共广播和私有广播时,都要声明,而且:1,先声明公共广播;2,私有action要在公共和私有里都addAction;3,接收是在公共接收器里处理结果的;4,先注销私有,再注销公共;但是会接收到两次广播 - publicReceiver = new PublicReceiver(); - IntentFilter filter = new IntentFilter(); - filter.addAction(BluetoothDevice.ACTION_FOUND);// 当一个设备被发现时,需要注册一个广播 - filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);// 千寻蓝牙配对完成 - filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);// 当显示检查完毕的时候,需要注册一个广播 - registerReceiver(publicReceiver, filter); - - // 初始化ArrayAdapter,一个是已经配对的设备,一个是新发现的设备 - mPairedDevicesArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_single_choice); - mNewDevicesArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_single_choice); - - // 检测并设置已配对的设备ListView - mPairedListView.setAdapter(mPairedDevicesArrayAdapter); - mPairedListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - mPairedListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - mNewDevicesListView.clearChoices(); - } - }); - - // 检查并设置行发现的蓝牙设备ListView - mNewDevicesListView.setAdapter(mNewDevicesArrayAdapter); - mNewDevicesListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - mNewDevicesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - mPairedListView.clearChoices(); - } - }); - - mSpinner1.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, ConnectTypeEnum.getRtkSupportConnectTypeNames())); - mSpinner2.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, RtkUtil.getSupportRTKEnumNames())); - - mSpinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - if (ConnectTypeEnum.getRtkSupportConnectTypes().contains(Device.getInstance().connectType)) { - Device.getInstance().connectType = ConnectTypeEnum.getRtkSupportConnectTypes().get(position); - } else { - Device.getInstance().connectType = ConnectTypeEnum.CONNECT_TYPE_SPP; - } - Util.putPreference("connectType", Device.getInstance().connectType.getValue()); - startService(); - updateBluetoothList(); - } - - @Override - public void onNothingSelected(AdapterView parent) { - - } - }); - - if (ConnectTypeEnum.getRtkSupportConnectTypes().contains(Device.getInstance().connectType)) { - mSpinner1.setSelection(ConnectTypeEnum.getRtkSupportConnectTypes().indexOf(Device.getInstance().connectType)); - } else { - mSpinner1.setSelection(0); - } - - mSpinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - Gnss.getInstance().lastRtkType = RTKEnum.values()[mSpinner2.getSelectedItemPosition()]; - Gnss.getInstance().save(); - - if (RTK.getInstance().getConnectTypeValue() == ConnectTypeEnum.CONNECT_TYPE_BLE.getValue()) { - if (ConnectTypeEnum.getRtkSupportConnectTypes().contains(ConnectTypeEnum.CONNECT_TYPE_BLE)) { - mSpinner1.setSelection(ConnectTypeEnum.getRtkSupportConnectTypes().indexOf(ConnectTypeEnum.CONNECT_TYPE_BLE)); - } else { - mSpinner1.setSelection(0); - } - } else if (RTK.getInstance() instanceof QxwzRTK) { - if (ConnectTypeEnum.getRtkSupportConnectTypes().contains(ConnectTypeEnum.CONNECT_TYPE_QXBT)) { - mSpinner1.setSelection(ConnectTypeEnum.getRtkSupportConnectTypes().indexOf(ConnectTypeEnum.CONNECT_TYPE_QXBT)); - } else { - mSpinner1.setSelection(0); - } - } - - Device.getInstance().deviceType = DeviceTypeEnum.DEVICE_TYPE_RTK; - Device.getInstance().deviceBrand = Gnss.getInstance().lastRtkType.getName(); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ConnectRtkActivity.this); - SharedPreferences.Editor editor = prefs.edit(); - editor.putInt("deviceType", Device.getInstance().deviceType.getValue()); - editor.putString("deviceBrand", Device.getInstance().deviceBrand); - editor.apply(); - } - - @Override - public void onNothingSelected(AdapterView parent) { - - } - }); - - if (AppChannel.customChannel == AppChannel.CUSTOM_SURVEY_SPACE || AppChannel.customChannel == AppChannel.CUSTOM_SURVEY_SPACE_INTERNATIONAL) { - Gnss.getInstance().lastRtkType = RTKEnum.RTK_SURVEY_SPACE; - mSpinner2.setEnabled(false); - mSpinner2.setVisibility(View.GONE); - } else if (AppChannel.customChannel == AppChannel.CUSTOM_FJD) { - Gnss.getInstance().lastRtkType = RTKEnum.RTK_FJD; - mSpinner2.setEnabled(false); - mSpinner2.setVisibility(View.GONE); - } else if (AppChannel.customChannel == AppChannel.CUSTOM_COMNAV) { - Gnss.getInstance().lastRtkType = RTKEnum.RTK_COMNAV; - mSpinner2.setEnabled(false); - mSpinner2.setVisibility(View.GONE); - } - - int index2 = RtkUtil.getSupportRTKEnum().indexOf(Gnss.getInstance().lastRtkType); - if (index2 == -1) index2 = 0; - mSpinner2.setSelection(index2); - -// mTextViewOneKeyFixAds.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View v) { -// finish(); -// EventBus.getDefault().post(new SingleMessageEvent("start_activity_one_key_fix")); -// } -// }); - - mBtnConnect.setText(Device.getInstance().isDeviceConnected()? "已连接": "连接"); - mBtnConnect.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - cancelScan(); - //如果是从全站仪切换过来的,先停止全站仪的线程 - TotalStation.getInstance().stopAll(); - if (Device.getInstance().isDeviceConnected()) { - ToastUtils.showShort(Rstring.device_has_connected_please_try_after_disconnect()); - } else { - if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_SPP - || Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_BLE - || Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_QXBT) { - String checkedInfo; - if (mPairedListView.getCheckedItemPosition() >= 0 && mPairedListView.getCheckedItemPosition() < mPairedDevicesArrayAdapter.getCount()) { - checkedInfo = mPairedDevicesArrayAdapter.getItem(mPairedListView.getCheckedItemPosition()); - } else if (mNewDevicesListView.getCheckedItemPosition() >= 0 && mNewDevicesListView.getCheckedItemPosition() < mNewDevicesArrayAdapter.getCount()) { - checkedInfo = mNewDevicesArrayAdapter.getItem(mNewDevicesListView.getCheckedItemPosition()); - } else { - ToastUtils.showShort(Rstring.please_choose_device_first()); - return; - } - // 得到mac地址 - String[] arr = checkedInfo.split("\n", 0); - if (arr.length != 2) { - return; - } - Device.getInstance().deviceBlueName = arr[0]; - Device.getInstance().deviceMacAddress = arr[1]; - Gnss.getInstance().getDevice().getBlue().setScanName(Device.getInstance().deviceBlueName); - Gnss.getInstance().getDevice().getBlue().setScanAddr(Device.getInstance().deviceMacAddress); - Gnss.getInstance().save(); - - if (DeviceUtil.checkIfNeedGnssServer()) { - if (DeviceUtil.checkIfGnssServerReady(ConnectRtkActivity.this)) {//先检查如果是千寻rtk,是否安装并打开了GnssServier - gnssServerReady = true; - } - } else { - requestLocationPermission(RC_LOCATION_PERM_CONNECT); - } - } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_PHONE_LOCATION) { - Device.getInstance().deviceBlueName = getString(Rstring.phone_location()); - Device.getInstance().deviceBrand = getString(Rstring.phone_location()); - requestLocationPermission(RC_LOCATION_PERM_CONNECT); - } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_EMULATOR) { - Device.getInstance().deviceBlueName = getString(Rstring.emulator_mode()); - Device.getInstance().deviceBrand = getString(Rstring.emulator_mode()); - try { - double lat = CoordUtil.dmsStringToRadian(item_starting_latitude.getRightText(), false); - double lon = CoordUtil.dmsStringToRadian(item_starting_longitude.getRightText(), false); - double alt = Double.parseDouble(item_starting_altitude.getRightText()); - float dir = 0; - if (!item_switch_random_direction.isChecked()) { - dir = (float) CoordUtil.dmsStringToRadian(item_starting_direction.getRightText(), false); - } - float speed = Float.parseFloat(item_move_speed.getRightText()); - - Device.getInstance().isEmulatorAngleRandom = item_switch_random_direction.isChecked(); - Device.getInstance().emulatorLat = lat; - Device.getInstance().emulatorLon = lon; - Device.getInstance().emulatorAlt = alt; - Device.getInstance().emulatorDirection = dir; - Device.getInstance().emulatorSpeed = speed; - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ConnectRtkActivity.this); - SharedPreferences.Editor editor = prefs.edit(); - editor.putString("emulatorLat", Device.getInstance().emulatorLat + ""); - editor.putString("emulatorLon", Device.getInstance().emulatorLon + ""); - editor.putString("emulatorAlt", Device.getInstance().emulatorAlt + ""); - editor.putFloat("emulatorDirection", Device.getInstance().emulatorDirection); - editor.putFloat("emulatorSpeed", Device.getInstance().emulatorSpeed); - editor.putBoolean("isEmulatorAngleRandom", Device.getInstance().isEmulatorAngleRandom); - editor.apply(); - Device.getInstance().requestConnect(); - } catch (NumberFormatException ex) { - ToastUtils.showShort(Rstring.invalid_input()); - return; - } - } - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ConnectRtkActivity.this); - SharedPreferences.Editor editor = prefs.edit(); - editor.putString("deviceBlueName", Device.getInstance().deviceBlueName); - editor.putString("deviceMacAddress", Device.getInstance().deviceMacAddress); - editor.apply(); - - // why ? - GnssPosition.getInstance().setXyz(new Coordinate()); - } - } - }); - - item_switch_random_direction.setOnSettingItemClick(new LSettingItem.onSettingItemClick() { - @Override - public void click(boolean isChecked) { - if (isChecked) { - item_starting_direction.setVisibility(View.GONE); - } else { - item_starting_direction.setVisibility(View.VISIBLE); - } - } - }); - - View paster = findViewById(com.bingce.device.ui.R.id.activity_setup_station_input_btn_paste); - if (paster != null) { - paster.setOnClickListener(view -> { - CharSequence clipboardUtilsString = ClipboardUtils.getText(); - if (clipboardUtilsString != null) { - String pasteString = clipboardUtilsString.toString(); - String[] arr = pasteString.split(",", -2); - if (arr.length == 3) { - try { - if (item_starting_latitude != null) { - item_starting_latitude.setRightText(arr[0]); - } - if (item_starting_longitude != null) { - item_starting_longitude.setRightText(arr[1]); - } - if (item_starting_altitude != null) { - item_starting_altitude.setRightText(arr[2]); - } - ToastUtils.showShort(Rstring.have_pasted()); - } catch (NumberFormatException ex) { - ToastUtils.showShort(Rstring.paste_format_error()); - } catch (Exception ex) { - ex.printStackTrace(); - } - } else { - ToastUtils.showShort(Rstring.paste_format_error()); - } - } - }); - } - } - - private void startService() { - switch (Device.getInstance().connectType) { - case CONNECT_TYPE_BLE: - layoutPairedDevices.setVisibility(View.VISIBLE); - layoutNewDevices.setVisibility(View.GONE); - layoutEmulator.setVisibility(View.GONE); - mTextViewTitleRtkType.setVisibility(View.VISIBLE); - mSpinner2.setVisibility(View.VISIBLE); - ServiceUtils.stopService(BTService.class); - ServiceUtils.stopService(TsSocketService.class); - ServiceUtils.stopService(EmulatorService.class); - ServiceUtils.stopService(NativePositioningService.class); - ServiceUtils.stopService(LocationService.class); - if (!ServiceUtils.isServiceRunning(BleService.class) && XXPermissions.isGranted(this, Permission.BLUETOOTH_CONNECT)) { - ServiceUtils.startService(BleService.class); - } - break; - case CONNECT_TYPE_PHONE_LOCATION: - layoutPairedDevices.setVisibility(View.GONE); - layoutNewDevices.setVisibility(View.GONE); - layoutEmulator.setVisibility(View.GONE); - mTextViewTitleRtkType.setVisibility(View.GONE); - mSpinner2.setVisibility(View.GONE); - ServiceUtils.stopService(BleService.class); - ServiceUtils.stopService(TsSocketService.class); - ServiceUtils.stopService(EmulatorService.class); - ServiceUtils.stopService(BTService.class); - ServiceUtils.stopService(LocationService.class); - if (!ServiceUtils.isServiceRunning(NativePositioningService.class)) { - ServiceUtils.startService(NativePositioningService.class); - ThreadPoolUtil.execute(() -> Device.getInstance().requestConnect(), 500); - } - break; - case CONNECT_TYPE_EMULATOR: - layoutPairedDevices.setVisibility(View.GONE); - layoutNewDevices.setVisibility(View.GONE); - layoutEmulator.setVisibility(View.VISIBLE); - mTextViewTitleRtkType.setVisibility(View.GONE); - mSpinner2.setVisibility(View.GONE); - item_starting_latitude.setRightText(CoordUtil.radianToDmsDoubleString(Device.getInstance().emulatorLat, 6, false)); - item_starting_longitude.setRightText(CoordUtil.radianToDmsDoubleString(Device.getInstance().emulatorLon, 6, false)); - item_starting_altitude.setRightText(CoordUtil.formatDouble2String(Device.getInstance().emulatorAlt)); - item_switch_random_direction.setChecked(Device.getInstance().isEmulatorAngleRandom); - if (Device.getInstance().isEmulatorAngleRandom) { - item_starting_direction.setVisibility(View.GONE); - } else { - item_starting_direction.setVisibility(View.VISIBLE); - } - item_starting_direction.setRightText(CoordUtil.radianToDmsDoubleString(Device.getInstance().emulatorDirection, 6, false)); - item_move_speed.setRightText(CoordUtil.formatDouble2String(Device.getInstance().emulatorSpeed)); - ServiceUtils.stopService(BleService.class); - ServiceUtils.stopService(TsSocketService.class); - ServiceUtils.stopService(BTService.class); - ServiceUtils.stopService(LocationService.class); - ServiceUtils.stopService(NativePositioningService.class); - if (!ServiceUtils.isServiceRunning(EmulatorService.class)) { - ServiceUtils.startService(EmulatorService.class); - } - break; - case CONNECT_TYPE_QXBT: - layoutPairedDevices.setVisibility(View.VISIBLE); - layoutNewDevices.setVisibility(View.GONE); - layoutEmulator.setVisibility(View.GONE); - mTextViewTitleRtkType.setVisibility(View.VISIBLE); - mSpinner2.setVisibility(View.VISIBLE); - ServiceUtils.stopService(BleService.class); - ServiceUtils.stopService(TsSocketService.class); - ServiceUtils.stopService(EmulatorService.class); - ServiceUtils.stopService(LocationService.class); - ServiceUtils.stopService(NativePositioningService.class); - ServiceUtils.stopService(BTService.class); - break; - default://CONNECT_TYPE_SPP - layoutPairedDevices.setVisibility(View.VISIBLE); - layoutNewDevices.setVisibility(View.GONE); - layoutEmulator.setVisibility(View.GONE); - mTextViewTitleRtkType.setVisibility(View.VISIBLE); - mSpinner2.setVisibility(View.VISIBLE); - ServiceUtils.stopService(BleService.class); - ServiceUtils.stopService(TsSocketService.class); - ServiceUtils.stopService(EmulatorService.class); - ServiceUtils.stopService(LocationService.class); - ServiceUtils.stopService(NativePositioningService.class); - if (!ServiceUtils.isServiceRunning(BTService.class) && XXPermissions.isGranted(this, Permission.BLUETOOTH_CONNECT)) { - ServiceUtils.startService(BTService.class); - } - } - } - - @SuppressLint("MissingPermission") - private boolean updateBluetoothList() { - if (!XXPermissions.isGranted(this, Permission.BLUETOOTH_CONNECT, Permission.ACCESS_FINE_LOCATION)) { - return false; - } - if (BluetoothAdapter.getDefaultAdapter() == null) { - ToastUtils.showShort(Rstring.bluetooth_is_not_available()); - return false; - } else { - //监测蓝牙是否开启 - if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) { - //打开蓝牙 - Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); - startActivityForResult(enableIntent, REQUEST_ENABLE_BT); - return false; - } else { - Device.getInstance().requestSetupChat(); - cancelScan(); - if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_SPP - || Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_BLE - || Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_QXBT) { - // 得到本地的蓝牙适配器 - mBtAdapter = BluetoothAdapter.getDefaultAdapter(); - if (mBtAdapter != null) { - // 得到一个已经匹配到本地适配器的BluetoothDevice类的对象集合 - Set pairedDevices = mBtAdapter.getBondedDevices(); - // 如果有配对成功的设备则添加到ArrayAdapter - if (!pairedDevices.isEmpty()) { - mPairedDevicesArrayAdapter.clear(); - for (BluetoothDevice device : pairedDevices) { - mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); - } - } else {// 否则添加一个没有被配对的字符串 - ToastUtils.showShort(Rstring.none_paired()); - } - - if (Device.getInstance().isDeviceConnected()) { - for (int i = 0; i < mPairedDevicesArrayAdapter.getCount(); i++) { - if (mPairedDevicesArrayAdapter.getItem(i) != null && mPairedDevicesArrayAdapter.getItem(i).endsWith(Device.getInstance().deviceMacAddress)) { - mPairedListView.setItemChecked(i, true); - ToastUtils.showShort(Rstring.device_has_connected()); - } else { - mPairedListView.setItemChecked(i, false); - } - } - } - } - } else { - mPairedDevicesArrayAdapter.clear(); - if (!"".equals(Device.getInstance().deviceBlueName) && !"".equals(Device.getInstance().deviceMacAddress)) { - mPairedDevicesArrayAdapter.add(Device.getInstance().deviceBlueName + "\n" + Device.getInstance().deviceMacAddress); - } - - if (Device.getInstance().isDeviceConnected()) { - mPairedListView.setItemChecked(0, true); - ToastUtils.showShort(Rstring.device_has_connected()); - } - } - return true; - } - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_activity_connect_rtk, menu); - if (AppUtils.isAppDebug()) { - menu.findItem(Rid.menu_activity_connect_rtk_comm_debug()).setVisible(true); - } - return super.onCreateOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - if (itemId == android.R.id.home) { - finish(); - } else if (itemId == Rid.menu_activity_connect_rtk_scan()) { - mNewDevicesArrayAdapter.clear(); - requestLocationPermission(RC_LOCATION_PERM_SCAN); - } else if (itemId == Rid.menu_activity_connect_rtk_disconnect()) { - Device.getInstance().requestDisconnect(); - for (int i = 0; i < mPairedDevicesArrayAdapter.getCount(); i++) { - mPairedListView.setItemChecked(i, false); - } - for (int i = 0; i < mNewDevicesArrayAdapter.getCount(); i++) { - mNewDevicesListView.setItemChecked(i, false); - } - mBtnConnect.setText("连接"); - } else if (itemId == Rid.menu_activity_connect_rtk_comm_debug()) { - startActivity(new Intent(this, ToolCommDebugActivity.class)); - } -// else if (itemId == Rid.menu_activity_connect_rtk_help()) { -// if (Utils.getApp() instanceof IHelper) { -// ((IHelper) Utils.getApp()).onNavigation2RtkConnectHelp(); -// } -// } - return super.onOptionsItemSelected(item); - } - - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onMessageEvent(RtkCmdSendOverEvent event) { - if (AppUtil.isForeground(this, this.getLocalClassName())) { - new AlertDialog.Builder(this) - .setTitle(Rstring.hint()) - .setMessage(Rstring.instrument_connection_completed()) - .setPositiveButton(Rstring.return_home_page(), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - finish(); - } - }) - .setNegativeButton(Rstring.close(), null) - .show(); - } - } - - - @SuppressLint("MissingPermission") - @Override - protected void onDestroy() { - super.onDestroy();// 确保我们没有发现,检测设备 - if (XXPermissions.isGranted(this, Permission.BLUETOOTH_SCAN) && mBtAdapter != null && mBtAdapter.isDiscovering()) { - mBtAdapter.cancelDiscovery(); - } - // 设置显示进度条 - setSupportProgressBarIndeterminateVisibility(false); - - unregisterReceiver(publicReceiver); - - EventBus.getDefault().unregister(this); - } - - @SuppressLint("MissingPermission") - private void doDiscovery() { - if (!XXPermissions.isGranted(this, Permission.BLUETOOTH_SCAN)) { - return; - } - //先断开已有连接 - Device.getInstance().requestDisconnect(); - // 显示新设备的子标题 - layoutNewDevices.setVisibility(View.VISIBLE); - cancelScan(); - // 如果已经在请求现实了,那么就先停止 - if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_SPP - || Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_QXBT) { - // 请求从蓝牙适配器得到能够被发现的设备 - if (mBtAdapter != null) { - mBtAdapter.startDiscovery(); - } - ToastUtils.showLong(Rstring.scanning()); - } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_BLE) { - BleScanner.getInstance().scan(null, null, null, false, 30000, new BleScanCallback() { - @Override - public void onScanFinished(List scanResultList) { - ToastUtils.showShort(com.bingce.device.ui.R.string.scan_complete); - } - - @Override - public void onScanStarted(boolean success) { - ToastUtils.showLong(Rstring.scanning()); - } - - @Override - public void onScanning(BleDevice bleDevice) { - if (bleDevice != null && bleDevice.getDevice().getBondState() != BluetoothDevice.BOND_BONDED) { - if (bleDevice.getName() == null) return; - String itemString = bleDevice.getName() + "\n" + bleDevice.getMac(); -// for (int i = 0; i < mPairedDevicesArrayAdapter.getCount(); i++) { -// if (itemString.equals(mPairedDevicesArrayAdapter.getItem(i))) { -// return; -// } -// } - int count = mNewDevicesArrayAdapter.getCount(); - if (count < 1) {//列表为空时,直接添加,不需要检查是否重复 - mNewDevicesArrayAdapter.add(itemString); - } else {//列表不为空时检查是否重复 - boolean has = false; - for (int j = 0; j < count; j++) { - if (itemString.equals(mNewDevicesArrayAdapter.getItem(j))) { - has = true; - break; - } - } - if (!has) { - mNewDevicesArrayAdapter.add(itemString); - } - } - } - } - }); - } - } - - /** - * 取消蓝牙扫描 - */ - @SuppressLint("MissingPermission") - private void cancelScan() { - if (!XXPermissions.isGranted(this, Permission.BLUETOOTH_SCAN)) { - return; - } - if (mBtAdapter != null && mBtAdapter.isDiscovering()) { - mBtAdapter.cancelDiscovery(); - } - if (BleManager.getInstance().getScanSate() == BleScanState.STATE_SCANNING) - BleManager.getInstance().cancelScan(); - } - - @SuppressLint("MissingPermission") - private void connect() { - if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_SPP - || Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_BLE - || Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_QXBT) { - - ToastUtils.showShort(Rstring.connecting_please_wait()); - - if (RTK.getInstance() instanceof QxwzRTK) { - Device.getInstance().connectType = ConnectTypeEnum.CONNECT_TYPE_QXBT; - - BluetoothDevice device = mBtAdapter.getRemoteDevice(Device.getInstance().deviceMacAddress); - if (device.getBondState() == BluetoothDevice.BOND_BONDED) { - ServiceUtils.startService(QxwzMessengerService.class); - } else {//新设备,利用反射配对 - try { - createBond(device); - } catch (Exception e) { - e.printStackTrace(); - } - } - } else { - Device.getInstance().requestConnect(); - } - } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_PHONE_LOCATION) { - Device.getInstance().requestConnect(); - } - } - - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - switch (requestCode) { - case REQUEST_ENABLE_BT: - if (resultCode == Activity.RESULT_OK) { - if (currentRequestCode == RC_BLUETOOTH_PERM_SCAN) { - requestBtScanPermission(); - } - } else { - Log.d("ConnectRtkActivity", "BT not enabled"); - ToastUtils.showShort(Rstring.bt_not_enabled()); - } - break; - } - if (requestCode == XXPermissions.REQUEST_CODE) { - switch (currentRequestCode) { - case RC_LOCATION_PERM_CONNECT: - if (XXPermissions.isGranted(this, Permission.ACCESS_FINE_LOCATION)) { - requestBtConnectPermission(); - } else { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_connection_requires_positioning_permission_please_turn_it_on_manually); - } - break; - case RC_LOCATION_PERM_SCAN: - if (XXPermissions.isGranted(this, Permission.ACCESS_FINE_LOCATION)) { - requestBtScanPermission(); - } else { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_scan_requires_positioning_permission_please_turn_it_on_manually); - } - break; - case RC_BLUETOOTH_PERM_CONNECT: - if (XXPermissions.isGranted(this, Permission.BLUETOOTH_CONNECT)) { - requestBtConnectPermission(); - } else { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_connection_requires_positioning_permission_please_turn_it_on_manually); - } - break; - case RC_BLUETOOTH_PERM_SCAN: - if (XXPermissions.isGranted(this, Permission.BLUETOOTH_SCAN)) { - requestBtScanPermission(); - } else { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_scan_requires_positioning_permission_please_turn_it_on_manually); - } - break; - } - } - } - - @Override - protected void onResume() { - super.onResume(); - if (gnssServerReady) { - new MaterialDialog.Builder(ConnectRtkActivity.this) - .title(Rstring.hint()) - .content(Rstring.you_need_start_gnss_server_for_communication()) - .positiveText(Rstring.started()) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - requestLocationPermission(RC_LOCATION_PERM_CONNECT); - } - }) - .negativeText(Rstring.cancel()) - .dismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - gnssServerReady = false; - } - }) - .show(); - } - } - - @Override - protected void onNewIntent(Intent intent) { - super.onNewIntent(intent); - //本来南方、千寻RTK调用GnssServer后返回到这个界面,应该使用onNewIntent,但是个别手机无法成功执行,在onResume里成功率会更高 - } - - /** - * 连接蓝牙先请求打开定位权限 - */ - public void requestLocationPermission(int type) { - currentRequestCode = type; - if (XXPermissions.isGranted(this, Permission.ACCESS_FINE_LOCATION, Permission.ACCESS_COARSE_LOCATION)) { - switch (type) { - case RC_LOCATION_PERM_SCAN: - requestBtScanPermission(); - break; - case RC_LOCATION_PERM_CONNECT: - requestBtConnectPermission(); - break; - } - } else { - new MaterialDialog.Builder(this) - .title(Rstring.location_permission()) - .content(Rstring.bluetooth_need_location_permission()) - .canceledOnTouchOutside(false) - .positiveText(Rstring.to_allow()) - .negativeText(Rstring.refuse()) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - XXPermissions.with(ConnectRtkActivity.this) - .permission(Permission.ACCESS_FINE_LOCATION, Permission.ACCESS_COARSE_LOCATION) - .request(new OnPermissionCallback() { - @Override - public void onGranted(List permissions, boolean all) { - if (all || permissions.contains(Permission.ACCESS_FINE_LOCATION)) { - startService(); - if (updateBluetoothList()) { - ThreadPoolUtil.executeInMain(new Runnable() { - @Override - public void run() { - switch (type) { - case RC_LOCATION_PERM_SCAN: - requestBtScanPermission(); - break; - case RC_LOCATION_PERM_CONNECT: - requestBtConnectPermission(); - break; - } - } - }, 500); - } - } - } - - @Override - public void onDenied(List permissions, boolean never) { - if (never) { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_connection_requires_positioning_permission_please_turn_it_on_manually); - // 如果是被永久拒绝就跳转到应用权限系统设置页面 - XXPermissions.startPermissionActivity(ConnectRtkActivity.this, permissions); - } else { - requestLocationPermission(type); - } - } - }); - } - }) - .onNegative(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - ToastUtils.showShort(com.bingce.device.ui.R.string.bluetooth_need_location_permission); - } - }) - .show(); - } - } - - public void requestBtScanPermission() { - currentRequestCode = RC_BLUETOOTH_PERM_SCAN; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - if (XXPermissions.isGranted(this, Permission.BLUETOOTH_SCAN, Permission.BLUETOOTH_CONNECT)) { - doDiscovery(); - } else { - new MaterialDialog.Builder(this) - .title(Rstring.bluetooth_scan_permission()) - .content(Rstring.bluetooth_scan_need_permission()) - .canceledOnTouchOutside(false) - .positiveText(Rstring.to_allow()) - .negativeText(Rstring.refuse()) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) { - XXPermissions.with(ConnectRtkActivity.this) - .permission(Permission.BLUETOOTH_SCAN, Permission.BLUETOOTH_CONNECT) - .request(new OnPermissionCallback() { - @Override - public void onGranted(List permissions, boolean all) { - if (all) { - startService(); - if (updateBluetoothList()) { - ThreadPoolUtil.executeInMain(new Runnable() { - @Override - public void run() { - doDiscovery(); - } - }, 500); - } - } else if (!permissions.contains(Permission.BLUETOOTH_SCAN)) { - requestBtScanPermission(); - } else if (!permissions.contains(Permission.BLUETOOTH_CONNECT)) { - requestBtConnectPermission(); - } - } - - @Override - public void onDenied(List permissions, boolean never) { - if (never) { - if (permissions.contains(Permission.BLUETOOTH_SCAN)) { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_connection_requires_positioning_permission_please_turn_it_on_manually); - // 如果是被永久拒绝就跳转到应用权限系统设置页面 - XXPermissions.startPermissionActivity(ConnectRtkActivity.this, Permission.BLUETOOTH_SCAN); - } else if (permissions.contains(Permission.BLUETOOTH_CONNECT)) { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_connection_requires_positioning_permission_please_turn_it_on_manually); - // 如果是被永久拒绝就跳转到应用权限系统设置页面 - XXPermissions.startPermissionActivity(ConnectRtkActivity.this, Permission.BLUETOOTH_CONNECT); - } - } else { - requestBtScanPermission(); - } - } - }); - } - }) - .onNegative(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - ToastUtils.showShort(com.bingce.device.ui.R.string.bluetooth_connect_need_permission); - } - }) - .show(); - - } - } else { - doDiscovery(); - } - } - - - public void requestBtConnectPermission() { - currentRequestCode = RC_BLUETOOTH_PERM_CONNECT; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - if (XXPermissions.isGranted(this, Permission.BLUETOOTH_CONNECT)) { - connect(); - } else { - new MaterialDialog.Builder(this) - .title(Rstring.bluetooth_connect_permission()) - .content(Rstring.bluetooth_connect_need_permission()) - .canceledOnTouchOutside(false) - .positiveText(Rstring.to_allow()) - .negativeText(Rstring.refuse()) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) { - XXPermissions.with(ConnectRtkActivity.this) - .permission(Permission.BLUETOOTH_CONNECT) - .request(new OnPermissionCallback() { - @Override - public void onGranted(List permissions, boolean all) { - startService(); - if (updateBluetoothList()) { - ThreadPoolUtil.executeInMain(new Runnable() { - @Override - public void run() { - connect(); - } - }, 500); - } - } - - @Override - public void onDenied(List permissions, boolean never) { - if (never) { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_connection_requires_positioning_permission_please_turn_it_on_manually); - // 如果是被永久拒绝就跳转到应用权限系统设置页面 - XXPermissions.startPermissionActivity(ConnectRtkActivity.this, Permission.BLUETOOTH_CONNECT); - } else { - requestBtConnectPermission(); - } - } - }); - } - }) - .onNegative(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - ToastUtils.showShort(com.bingce.device.ui.R.string.bluetooth_connect_need_permission); - } - }) - .show(); - } - } else { - connect(); - } - } - - class PublicReceiver extends BroadcastReceiver { - @SuppressLint("MissingPermission") - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - // 当发现一个设备时 - if (BluetoothDevice.ACTION_FOUND.equals(action)) { - if (!XXPermissions.isGranted(ConnectRtkActivity.this, Permission.BLUETOOTH_CONNECT, Permission.ACCESS_FINE_LOCATION)) { - return; - } - // 从Intent得到蓝牙设备对象 - BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); - // 如果已经配对,则跳过,因为他已经在设备列表中了 - if (device != null && device.getName() != null/* && device.getBondState() != BluetoothDevice.BOND_BONDED*/) { - // 显示新设备 - layoutNewDevices.setVisibility(View.VISIBLE); - // 否则添加到新设备列表 - int count = mNewDevicesArrayAdapter.getCount(); - String itemString = device.getName() + "\n" + device.getAddress(); - if (count < 1) {//列表为空时,直接添加,不需要检查是否重复 - mNewDevicesArrayAdapter.add(itemString); - } else {//列表不为空时检查是否重复 - boolean has = false; - for (int i = 0; i < count; i++) { - if (itemString.equals(mNewDevicesArrayAdapter.getItem(i))) { - has = true; - break; - } - } - if (!has) { - mNewDevicesArrayAdapter.add(itemString); - } - } - } - } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { - // 如果计数为0,则表示没有发现蓝牙 - if (mNewDevicesArrayAdapter.getCount() == 0) { - ToastUtils.showShort(Rstring.discovery_finished()); - } - } else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) { - //新设备使用千寻蓝牙时配对 - int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1); - int prestate = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, -1); - Log.d("ConnectRtkActivity", "ACTION_BOND_STATE_CHANGED" + ",state:" + state + ",prestate:" + prestate); - if (state == BluetoothDevice.BOND_BONDED && prestate == BluetoothDevice.BOND_BONDING) { - if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_QXBT) { - ServiceUtils.startService(QxwzMessengerService.class); - Log.d("ConnectRtkActivity", "反射配对成功"); - } - } - } - } - } - - public static void start() { - ActivityUtils.startActivity(ConnectRtkActivity.class); - } - - /** - * 蓝牙配对 - * - * @param device - * @return - * @throws Exception - */ - public static boolean createBond(BluetoothDevice device) throws Exception { - Method createBondMethod = BluetoothDevice.class.getMethod("createBond"); - return (Boolean) createBondMethod.invoke(device); - } - - public interface IHelper { - void onNavigation2RtkConnectHelp(); - } -} diff --git a/app/src/main/java/com/project/survey/ui/instrument/setupstation/EditCoordinatePointActivity.java b/app/src/main/java/com/project/survey/ui/instrument/setupstation/EditCoordinatePointActivity.java index 20c3285..4ec9a47 100644 --- a/app/src/main/java/com/project/survey/ui/instrument/setupstation/EditCoordinatePointActivity.java +++ b/app/src/main/java/com/project/survey/ui/instrument/setupstation/EditCoordinatePointActivity.java @@ -68,7 +68,7 @@ public class EditCoordinatePointActivity extends BaseSurveyNewActivity { if (pointRecord.deviceInfoData.tsStatusData != null) { TSStatusData pointRecordTSInfo = pointRecord.deviceInfoData.tsStatusData; - TSStatusData tsStatusData = new TSStatusData(pointRecordTSInfo.deviceType, pointRecordTSInfo.x, pointRecordTSInfo.y, pointRecordTSInfo.z, inputHrDouble, pointRecordTSInfo.setupStationMethod, pointRecordTSInfo.stationName, pointRecordTSInfo.stationX, pointRecordTSInfo.stationY, pointRecordTSInfo.stationZ, pointRecordTSInfo.hi, pointRecordTSInfo.ha, pointRecordTSInfo.va, pointRecordTSInfo.sd, pointRecordTSInfo.angleDifference, pointRecordTSInfo.powerLevel, pointRecordTSInfo.backSightPoints, pointRecordTSInfo.checkPoints, pointRecordTSInfo.deviceModel, pointRecordTSInfo.deviceSn); + TSStatusData tsStatusData = new TSStatusData(pointRecordTSInfo.deviceType, pointRecordTSInfo.x, pointRecordTSInfo.y, pointRecordTSInfo.z, inputHrDouble, pointRecordTSInfo.setupStationMethod, pointRecordTSInfo.stationName, pointRecordTSInfo.stationX, pointRecordTSInfo.stationY, pointRecordTSInfo.stationZ, pointRecordTSInfo.hi, pointRecordTSInfo.ha, pointRecordTSInfo.va, pointRecordTSInfo.sd, pointRecordTSInfo.angleDifference, pointRecordTSInfo.powerLevel, pointRecordTSInfo.backSightPoints, pointRecordTSInfo.checkPoints, pointRecordTSInfo.deviceModel, pointRecordTSInfo.deviceSn, pointRecordTSInfo.prismTypeCode, pointRecordTSInfo.prismConstant, pointRecordTSInfo.prismTypeName); DeviceInfoData deviceInfoData = new DeviceInfoData(tsStatusData); pointRecord.deviceInfoData = deviceInfoData; } diff --git a/app/src/main/java/com/project/survey/ui/instrument/setupstation/util/JobDbUtils.java b/app/src/main/java/com/project/survey/ui/instrument/setupstation/util/JobDbUtils.java index 5e154f1..e3ca977 100644 --- a/app/src/main/java/com/project/survey/ui/instrument/setupstation/util/JobDbUtils.java +++ b/app/src/main/java/com/project/survey/ui/instrument/setupstation/util/JobDbUtils.java @@ -228,7 +228,7 @@ public class JobDbUtils { @WorkerThread public static String createDefaultJob(Context context, String projectId, long time) { - JobRecord jobRecord = new JobRecord(context.getString(R.string.default_work_name), projectId, time); + JobRecord jobRecord = new JobRecord("默认作业", projectId, time); JobDb.getInstance().save(jobRecord); KeyValueRecord defaultJobConfig = new KeyValueRecord(KeyValueConstants.keyOfProjectCurrentJob(projectId), jobRecord.id); diff --git a/app/src/main/java/com/project/survey/ui/instrument/totalstation/ConnectTSActivity.java b/app/src/main/java/com/project/survey/ui/instrument/totalstation/ConnectTSActivity.java deleted file mode 100644 index 1040f07..0000000 --- a/app/src/main/java/com/project/survey/ui/instrument/totalstation/ConnectTSActivity.java +++ /dev/null @@ -1,1154 +0,0 @@ -package com.project.survey.ui.instrument.totalstation; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.app.AlertDialog; -import android.bluetooth.BluetoothAdapter; -import android.bluetooth.BluetoothDevice; -import android.content.BroadcastReceiver; -import android.content.ComponentName; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.SharedPreferences; -import android.graphics.Color; -import android.net.wifi.WifiManager; -import android.os.Build; -import android.os.Bundle; -import android.provider.Settings; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.ListView; -import android.widget.Spinner; - -import androidx.annotation.NonNull; -import androidx.appcompat.widget.Toolbar; -import androidx.fragment.app.Fragment; -import androidx.preference.PreferenceManager; - -import com.afollestad.materialdialogs.DialogAction; -import com.afollestad.materialdialogs.MaterialDialog; -import com.bingce.AppChannel; -import com.bingce.coordlib.model.Coordinate; -import com.bingce.device.Device; -import com.bingce.device.enums.ConnectTypeEnum; -import com.bingce.device.enums.DeviceTypeEnum; -import com.bingce.device.service.comm.ble.BleService; -import com.bingce.device.service.comm.emulator.EmulatorService; -import com.bingce.device.service.comm.localgps.LocationService; -import com.bingce.device.service.comm.localgps.NativePositioningService; -import com.bingce.device.service.comm.otg.OTGCommService; -import com.bingce.device.service.comm.socket.TsSocketService; -import com.bingce.device.service.comm.spp.BTService; -import com.bingce.device.ui.ToolCommDebugActivity; -import com.bingce.event.OpenShortUrlEvent; -import com.bingce.rtk.gnss.Gnss; -import com.bingce.totalstation.TotalStation; -import com.bingce.totalstation.TsConfig; -import com.bingce.totalstation.TsListener; -import com.bingce.totalstation.enums.CommDelayEnum; -import com.bingce.totalstation.enums.SetupStationModeEnum; -import com.bingce.totalstation.enums.TotalStationEnum; -import com.bingce.totalstation.protocol.topcon.TopconInterface; -import com.bingce.totalstation.util.TsUtil; -import com.bingce.utils.RomUtil; -import com.bingce.utils.SoftKeyUtils; -import com.bingce.utils.ThreadPoolUtil; -import com.bingce.utils.Util; -import com.bingce.utils.ValidateUtil; -import com.hjq.permissions.OnPermissionCallback; -import com.hjq.permissions.Permission; -import com.hjq.permissions.XXPermissions; -import com.rengwuxian.materialedittext.MaterialEditText; - -import org.greenrobot.eventbus.EventBus; -import org.polaric.colorful.ColorfulActivity; - -import java.util.Arrays; -import java.util.List; -import java.util.Locale; -import java.util.Set; -import java.util.regex.Pattern; - -import blankj.utilcode.util.ActivityUtils; -import blankj.utilcode.util.AppUtils; -import blankj.utilcode.util.ServiceUtils; -import blankj.utilcode.util.StringUtils; -import blankj.utilcode.util.ToastUtils; -import blankj.utilcode.util.Utils; -import clj.fastble.BleManager; -import clj.fastble.callback.BleScanCallback; -import clj.fastble.data.BleDevice; -import clj.fastble.data.BleScanState; -import clj.fastble.scan.BleScanner; -import device.ui.Rid; -import device.ui.Rlayout; -import device.ui.Rmenu; -import device.ui.Rstring; - -public class ConnectTSActivity extends ColorfulActivity implements TsListener.TsTestListener { - private static final int RC_LOCATION_PERM_SCAN = 128; - private static final int RC_LOCATION_PERM_CONNECT = 129; - private static final int RC_BLUETOOTH_PERM_SCAN = 130; - private static final int RC_BLUETOOTH_PERM_CONNECT = 131; - private static final int REQUEST_ENABLE_BT = 3; - public static final int WIFI_AP_STATE_ENABLED = 13; - private int currentRequestCode = -1; - private BluetoothAdapter mBtAdapter; - private ArrayAdapter mPairedDevicesArrayAdapter; - private ArrayAdapter mNewDevicesArrayAdapter; - private MaterialEditText met_coord_prefix_x, met_coord_prefix_y, met_coord_prefix_z; - private PublicReceiver publicReceiver; - private Toolbar mToolbar; - private Spinner mSpinner1; - private Spinner mSpinner2; - private Spinner mSpinner3; - private ListView mPairedListView; - private LinearLayout layoutPairedDevices; - private ListView mNewDevicesListView; - private LinearLayout layoutNewDevices; - private MaterialEditText met_ip, met_port; - private MaterialEditText met_tp_com_blue_mac, met_otg_tp_com_mac; - private Button mBtnOpenHotspot, mBtnHotspotConnect; - private Button mBtnTpComConnect, mBtnOTGConnect; - private LinearLayout layoutWifiHotspotSetting, layoutTpComSetting, layoutOTGSetting; - private Button mBtnTest; - private Button mBtnGuide; - private Button mBtnTaobao; - - @SuppressLint("SourceLockedOrientationActivity") - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(Rlayout.activity_connect_total_station()); - mToolbar = findViewById(Rid.toolbar()); - mSpinner1 = findViewById(Rid.activity_connect_total_station_spinner_connect_type()); - mSpinner2 = findViewById(Rid.activity_connect_total_station_spinner_total_station_type()); - mSpinner3 = findViewById(Rid.activity_connect_total_station_spinner_com_delay()); - mPairedListView = findViewById(Rid.activity_connect_total_station_paired_devices()); - layoutPairedDevices = findViewById(Rid.activity_connect_total_station_layout_paired_devices()); - mNewDevicesListView = findViewById(Rid.activity_connect_total_station_new_devices()); - layoutNewDevices = findViewById(Rid.activity_connect_total_station_layout_new_devices()); - met_ip = findViewById(Rid.met_activity_connect_total_station_wifi_ip()); - met_port = findViewById(Rid.met_activity_connect_total_station_wifi_port()); - met_tp_com_blue_mac = findViewById(Rid.met_activity_connect_total_station_tp_com_bluetooth_mac()); - met_otg_tp_com_mac = findViewById(Rid.met_activity_connect_total_station_otg_tp_com_mac()); - mBtnOpenHotspot = findViewById(Rid.activity_connect_total_station_btn_wifi_hotspot_open()); - mBtnHotspotConnect = findViewById(Rid.activity_connect_total_station_btn_wifi_connect()); - mBtnTpComConnect = findViewById(Rid.activity_connect_total_station_btn_tp_com_connect()); - mBtnOTGConnect = findViewById(Rid.activity_connect_total_station_btn_otg_connect()); - layoutWifiHotspotSetting = findViewById(Rid.activity_connect_total_station_layout_wifi_setting()); - layoutTpComSetting = findViewById(Rid.activity_connect_total_station_layout_tp_com_setting()); - layoutOTGSetting = findViewById(Rid.activity_connect_total_station_layout_otg_setting()); - mBtnTest = findViewById(Rid.activity_connect_total_station_btn_test()); - mBtnGuide = findViewById(Rid.activity_connect_total_station_btn_guide()); - mBtnTaobao = findViewById(Rid.activity_connect_total_station_taobao()); - String packageName = getPackageName(); -// if ("com.bingce.controlnetwork.tj".equals(packageName) -// || "com.bingce.controlnetwork.tj.leveling".equals(packageName) -// || "com.bingce.controlnetwork.pla".equals(packageName)) { - mBtnGuide.setVisibility(View.GONE); - mBtnTaobao.setVisibility(View.GONE); -// } - - TsListener.getInstance().addTsTestListener(this); - - setSupportActionBar(mToolbar); - if (getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - //当存在公共广播和私有广播时,都要声明,而且:1,先声明公共广播;2,私有action要在公共和私有里都addAction;3,接收是在公共接收器里处理结果的;4,先注销私有,再注销公共 - publicReceiver = new PublicReceiver(); - IntentFilter filter = new IntentFilter(); - filter.addAction(BluetoothDevice.ACTION_FOUND);// 当一个设备被发现时,需要注册一个广播 - filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);// 当显示检查完毕的时候,需要注册一个广播 - registerReceiver(publicReceiver, filter); - - mSpinner1.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, ConnectTypeEnum.getTsSupportConnectTypeNames())); - mSpinner2.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, TsUtil.getSupportTotalStationEnumNames())); - mSpinner3.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, TsUtil.getCommDelayEnumNames())); - mBtnTest.setOnClickListener(listener); -// mBtnGuide.setOnClickListener(listener); -// mBtnTaobao.setOnClickListener(listener); - - // 初始化ArrayAdapter,一个是已经配对的设备,一个是新发现的设备 - mPairedDevicesArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_single_choice); - mNewDevicesArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_single_choice); - - // 检测并设置已配对的设备ListView - mPairedListView.setAdapter(mPairedDevicesArrayAdapter); - mPairedListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - mPairedListView.setOnItemClickListener(mDeviceClickListener); - - // 检查并设置行发现的蓝牙设备ListView - mNewDevicesListView.setAdapter(mNewDevicesArrayAdapter); - mNewDevicesListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); - mNewDevicesListView.setOnItemClickListener(mDeviceClickListener); - - mSpinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parent, View view, int position, long id) { - if (ConnectTypeEnum.getTsSupportConnectTypes().contains(Device.getInstance().connectType)) { - Device.getInstance().connectType = ConnectTypeEnum.getTsSupportConnectTypes().get(position); - } else { - Device.getInstance().connectType = ConnectTypeEnum.CONNECT_TYPE_SPP; - } - Util.putPreference("connectType", Device.getInstance().connectType.getValue()); - - startService(); - updateBluetoothList(); - } - - @Override - public void onNothingSelected(AdapterView parent) { - - } - }); - - if (TsConfig.getInstance().lastTsType.getConnectTypeValue() >= 0 && TsConfig.getInstance().lastTsType.getConnectTypeValue() < mSpinner1.getCount()) { - mSpinner1.setSelection(TsConfig.getInstance().lastTsType.getConnectTypeValue()); - } - - mSpinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView adapterView, View view, int position, long l) { - TsConfig.getInstance().lastTsType = TsUtil.getSupportTotalStationEnums().get(mSpinner2.getSelectedItemPosition()); - TsConfig.getInstance().save(); - - if (mSpinner1.getSelectedItemPosition() != 3) {//OTG - if (TsConfig.getInstance().lastTsType.getConnectTypeValue() >= 0 && TsConfig.getInstance().lastTsType.getConnectTypeValue() < mSpinner1.getCount()) { - mSpinner1.setSelection(TsConfig.getInstance().lastTsType.getConnectTypeValue()); - } - } - switch (TsConfig.getInstance().lastTsType) { - case TOTAL_STATION_HAIYUN_BOIF: - case TOTAL_STATION_RUIDE: - case TOTAL_STATION_GEODIMETER2: - case TOTAL_STATION_SOUTH_5XX_ANDROID_BT: - mSpinner3.setVisibility(View.VISIBLE); - break; - default: - mSpinner3.setVisibility(View.GONE); - } - if (TsConfig.getInstance().lastTsType == TotalStationEnum.TOTAL_STATION_TRIMBLE_TPCOM) { - if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_OTG) { - met_otg_tp_com_mac.setVisibility(View.VISIBLE); - } else { - met_otg_tp_com_mac.setVisibility(View.GONE); - } - } else { - met_otg_tp_com_mac.setVisibility(View.GONE); - } - - Device.getInstance().deviceType = DeviceTypeEnum.DEVICE_TYPE_TS; - Device.getInstance().deviceBrand = TsConfig.getInstance().lastTsType.getName(); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ConnectTSActivity.this); - SharedPreferences.Editor editor = prefs.edit(); - editor.putInt("deviceType", DeviceTypeEnum.DEVICE_TYPE_TS.getValue()); - editor.putString("deviceBrand", Device.getInstance().deviceBrand); - editor.apply(); - } - - @Override - public void onNothingSelected(AdapterView adapterView) { - - } - }); - - if (AppChannel.customChannel == AppChannel.CUSTOM_NMP) { - TsConfig.getInstance().lastTsType = TotalStationEnum.TOTAL_STATION_NEWMAP; - mSpinner2.setEnabled(false); - } else if (AppChannel.customChannel == AppChannel.CUSTOM_HUACE) { - TsConfig.getInstance().lastTsType = TotalStationEnum.TOTAL_STATION_HUACE; - mSpinner2.setEnabled(false); - } else if (AppChannel.customChannel == AppChannel.CUSTOM_UFO) { - TsConfig.getInstance().lastTsType = TotalStationEnum.TOTAL_STATION_UFO_T5; - mSpinner2.setEnabled(false); - } else if (AppChannel.customChannel == AppChannel.CUSTOM_PENTAX || AppChannel.customChannel == AppChannel.CUSTOM_PENTAX_INTERNATIONAL) { - TsConfig.getInstance().lastTsType = TotalStationEnum.TOTAL_STATION_PENTAX_X100; - mSpinner2.setEnabled(false); - } - - int index2 = TsUtil.getSupportTotalStationEnums().indexOf(TsConfig.getInstance().lastTsType); - if (index2 == -1) index2 = 0; - mSpinner2.setSelection(index2); - - int index3 = Arrays.asList(CommDelayEnum.values()).indexOf(TsConfig.getInstance().getCommDelay()); - if (index3 == -1) index3 = 0; - mSpinner3.setSelection(index3); - mSpinner3.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView arg0, View arg1, int position, long id) { - TsConfig.getInstance().setCommDelay(CommDelayEnum.values()[position]); - TsConfig.getInstance().save(); - } - - @Override - public void onNothingSelected(AdapterView arg0) { - - } - }); - - met_ip.setText(TsConfig.getInstance().getIp()); - met_port.setText(String.format(Locale.US, "%d", TsConfig.getInstance().getPort())); - mBtnOpenHotspot.setOnClickListener((v) -> { - if (isWifiApOpen()) { - ToastUtils.showShort(Rstring.hotspot_open_success()); - } else { - //打开网络共享与热点设置页面 - if (RomUtil.isOppo() || RomUtil.isLenove() || RomUtil.isGionee()) { - //OPPO系统系统特殊,会让在Manifest.xml声明Settings$TetherSettingsActivity,现在让用户自己找热点界面,并开启 - ToastUtils.showShort(Rstring.find_tether_setting_and_open()); - startActivity(new Intent(Settings.ACTION_SETTINGS)); - } else { - Intent intent = new Intent(); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - ComponentName comp = new ComponentName("com.android.settings", "com.android.settings.Settings$TetherSettingsActivity"); - intent.setComponent(comp); - startActivity(intent); - } - } - }); - - mBtnHotspotConnect.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (!ValidateUtil.isIPAddress(met_ip.getText().toString().trim())) { - ToastUtils.showShort(Rstring.please_input_correct_ip()); - return; - } - try { - Integer.parseInt(met_port.getText().toString().trim()); - TsConfig.getInstance().setIp(met_ip.getText().toString().trim()); - TsConfig.getInstance().setPort(Integer.parseInt(met_port.getText().toString().trim())); - TsConfig.getInstance().save(); - } catch (NumberFormatException ex) { - ToastUtils.showShort(Rstring.please_input_correct_port()); - return; - } - if (isWifiApOpen()) { - ServiceUtils.stopService(EmulatorService.class); - ServiceUtils.stopService(LocationService.class); - ServiceUtils.stopService(NativePositioningService.class); - ServiceUtils.stopService(BTService.class); - ServiceUtils.stopService(BleService.class); - Device.getInstance().requestConnect(); - - Device.getInstance().deviceBlueName = TsConfig.getInstance().getIp(); - Device.getInstance().deviceMacAddress = ""; - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ConnectTSActivity.this); - SharedPreferences.Editor editor = prefs.edit(); - editor.putString("deviceBlueName", Device.getInstance().deviceBlueName); - editor.putString("deviceMacAddress", Device.getInstance().deviceMacAddress); - editor.apply(); - } else { - ToastUtils.showShort(Rstring.please_open_hotspot_first()); - } - } - }); - - met_tp_com_blue_mac.setText(TsConfig.getInstance().getTpComMac()); - mBtnTpComConnect.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (!AppUtils.isAppInstalled("com.tpcom")) { - ToastUtils.showShort(Rstring.tp_com_not_installed()); - return; - } - String tpComMac = met_tp_com_blue_mac.getText().toString(); - if (!Pattern.matches("/^[A-F0-9]{2}(-[A-F0-9]{2}){5}$|^[A-F0-9]{2}(:[A-F0-9]{2}){5}$|^[A-F0-9]{12}$|^[A-F0-9]{4}(\\.[A-F0-9]{4}){2}$", tpComMac)) { - ToastUtils.showShort(Rstring.please_input_correct_mac()); - return; - } - TsConfig.getInstance().setIp("127.0.0.1"); - TsConfig.getInstance().setPort(8090); - TsConfig.getInstance().setTpComMac(tpComMac); - TsConfig.getInstance().save(); - Device.getInstance().requestConnect(); - - Device.getInstance().deviceBlueName = "TP COM"; - Device.getInstance().deviceMacAddress = tpComMac; - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ConnectTSActivity.this); - SharedPreferences.Editor editor = prefs.edit(); - editor.putString("deviceBlueName", Device.getInstance().deviceBlueName); - editor.putString("deviceMacAddress", Device.getInstance().deviceMacAddress); - editor.apply(); - } - }); - met_otg_tp_com_mac.setText(TsConfig.getInstance().getTpComMac()); - mBtnOTGConnect.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - ServiceUtils.stopService(BTService.class); - ServiceUtils.stopService(BleService.class); - ServiceUtils.stopService(TsSocketService.class); - ServiceUtils.stopService(EmulatorService.class); - - if (TsConfig.getInstance().lastTsType == TotalStationEnum.TOTAL_STATION_TRIMBLE_TPCOM) { - String tpComMac = met_otg_tp_com_mac.getText().toString(); - if (!Pattern.matches("/^[A-F0-9]{2}(-[A-F0-9]{2}){5}$|^[A-F0-9]{2}(:[A-F0-9]{2}){5}$|^[A-F0-9]{12}$|^[A-F0-9]{4}(\\.[A-F0-9]{4}){2}$", tpComMac)) { - ToastUtils.showShort(Rstring.please_input_correct_mac()); - return; - } - TsConfig.getInstance().setIp("127.0.0.1"); - TsConfig.getInstance().setPort(8090); - TsConfig.getInstance().setTpComMac(tpComMac); - TsConfig.getInstance().save(); - } - Device.getInstance().requestConnect(); - - Device.getInstance().deviceBlueName = "OTG"; - Device.getInstance().deviceMacAddress = ""; - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ConnectTSActivity.this); - SharedPreferences.Editor editor = prefs.edit(); - editor.putString("deviceBlueName", Device.getInstance().deviceBlueName); - editor.putString("deviceMacAddress", Device.getInstance().deviceMacAddress); - editor.apply(); - } - }); - } - - private void startService() { - if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_SPP) { - layoutPairedDevices.setVisibility(View.VISIBLE); - layoutNewDevices.setVisibility(View.GONE); - layoutWifiHotspotSetting.setVisibility(View.GONE); - layoutTpComSetting.setVisibility(View.GONE); - layoutOTGSetting.setVisibility(View.GONE); - ServiceUtils.stopService(BleService.class); - ServiceUtils.stopService(OTGCommService.class); - ServiceUtils.stopService(TsSocketService.class); - ServiceUtils.stopService(EmulatorService.class); - ServiceUtils.stopService(NativePositioningService.class); - if (!ServiceUtils.isServiceRunning(BTService.class) && XXPermissions.isGranted(this, Permission.BLUETOOTH_CONNECT)) { - ServiceUtils.startService(BTService.class); - } - } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_BLE) { - layoutPairedDevices.setVisibility(View.VISIBLE); - layoutNewDevices.setVisibility(View.GONE); - layoutWifiHotspotSetting.setVisibility(View.GONE); - layoutTpComSetting.setVisibility(View.GONE); - layoutOTGSetting.setVisibility(View.GONE); - ServiceUtils.stopService(BTService.class); - ServiceUtils.stopService(OTGCommService.class); - ServiceUtils.stopService(TsSocketService.class); - ServiceUtils.stopService(EmulatorService.class); - ServiceUtils.stopService(NativePositioningService.class); - if (!ServiceUtils.isServiceRunning(BleService.class) && XXPermissions.isGranted(this, Permission.BLUETOOTH_CONNECT)) { - ServiceUtils.startService(BleService.class); - } - } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_HOTSPOT) { - layoutPairedDevices.setVisibility(View.GONE); - layoutNewDevices.setVisibility(View.GONE); - layoutWifiHotspotSetting.setVisibility(View.VISIBLE); - layoutTpComSetting.setVisibility(View.GONE); - layoutOTGSetting.setVisibility(View.GONE); - ServiceUtils.stopService(BTService.class); - ServiceUtils.stopService(BleService.class); - ServiceUtils.stopService(OTGCommService.class); - ServiceUtils.stopService(EmulatorService.class); - ServiceUtils.stopService(NativePositioningService.class); - if (!ServiceUtils.isServiceRunning(TsSocketService.class)) { - ServiceUtils.startService(TsSocketService.class); - } - } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_OTG) { - layoutPairedDevices.setVisibility(View.GONE); - layoutNewDevices.setVisibility(View.GONE); - layoutWifiHotspotSetting.setVisibility(View.GONE); - layoutTpComSetting.setVisibility(View.GONE); - layoutOTGSetting.setVisibility(View.VISIBLE); - if (TsConfig.getInstance().lastTsType == TotalStationEnum.TOTAL_STATION_TRIMBLE_TPCOM) { - met_otg_tp_com_mac.setVisibility(View.VISIBLE); - } else { - met_otg_tp_com_mac.setVisibility(View.GONE); - } - ServiceUtils.stopService(BTService.class); - ServiceUtils.stopService(BleService.class); - ServiceUtils.stopService(TsSocketService.class); - ServiceUtils.stopService(EmulatorService.class); - ServiceUtils.stopService(NativePositioningService.class); - if (!ServiceUtils.isServiceRunning(OTGCommService.class)) { - ServiceUtils.startService(OTGCommService.class); - } - } else if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_TPCOM) { - layoutPairedDevices.setVisibility(View.GONE); - layoutNewDevices.setVisibility(View.GONE); - layoutWifiHotspotSetting.setVisibility(View.GONE); - layoutTpComSetting.setVisibility(View.VISIBLE); - layoutOTGSetting.setVisibility(View.GONE); - ServiceUtils.stopService(BTService.class); - ServiceUtils.stopService(BleService.class); - ServiceUtils.stopService(OTGCommService.class); - ServiceUtils.stopService(EmulatorService.class); - ServiceUtils.stopService(NativePositioningService.class); - if (!ServiceUtils.isServiceRunning(TsSocketService.class)) { - ServiceUtils.startService(TsSocketService.class); - } - } - } - - @SuppressLint("MissingPermission") - private boolean updateBluetoothList() { - if (!XXPermissions.isGranted(this, Permission.BLUETOOTH_CONNECT, Permission.ACCESS_FINE_LOCATION)) { - return false; - } - if (BluetoothAdapter.getDefaultAdapter() == null) { - ToastUtils.showLong(Rstring.bluetooth_is_not_available()); - return false; - } else { - //监测蓝牙是否开启 - if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) { - //打开蓝牙 - Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); - startActivityForResult(enableIntent, REQUEST_ENABLE_BT); - return false; - } else { - Device.getInstance().requestSetupChat(); - cancelScan(); - if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_SPP) { - // 得到本地的蓝牙适配器 - mBtAdapter = BluetoothAdapter.getDefaultAdapter(); - if (mBtAdapter != null) { - // 得到一个已经匹配到本地适配器的BluetoothDevice类的对象集合 - Set pairedDevices = mBtAdapter.getBondedDevices(); - // 如果有配对成功的设备则添加到ArrayAdapter - if (pairedDevices.size() > 0) { - mPairedDevicesArrayAdapter.clear(); - for (BluetoothDevice device : pairedDevices) { - mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); - } - } else {// 否则添加一个没有被配对的字符串 - ToastUtils.showShort(Rstring.none_paired()); - } - - if (Device.getInstance().isDeviceConnected()) { - for (int i = 0; i < mPairedDevicesArrayAdapter.getCount(); i++) { - if (mPairedDevicesArrayAdapter.getItem(i) != null && mPairedDevicesArrayAdapter.getItem(i).endsWith(Device.getInstance().deviceMacAddress)) { - mPairedListView.setItemChecked(i, true); - ToastUtils.showShort(Rstring.device_has_connected()); - } else { - mPairedListView.setItemChecked(i, false); - } - } - } - } - } else { - mPairedDevicesArrayAdapter.clear(); - if (!"".equals(Device.getInstance().deviceBlueName) && !"".equals(Device.getInstance().deviceMacAddress)) { - mPairedDevicesArrayAdapter.add(Device.getInstance().deviceBlueName + "\n" + Device.getInstance().deviceMacAddress); - } - - if (Device.getInstance().isDeviceConnected()) { - mPairedListView.setItemChecked(0, true); - ToastUtils.showShort(Rstring.device_has_connected()); - } - } - return true; - } - } - } - - /** - * ListViews中所有设备的点击事件监听 - */ - private final AdapterView.OnItemClickListener mDeviceClickListener = new AdapterView.OnItemClickListener() { - public void onItemClick(AdapterView av, View v, int arg2, long arg3) { - cancelScan(); - //如果是从RTK切换过来的,先停止RTK的线程 -// if (!"com.bingce.controlnetwork".equals(getPackageName())) - Device.getInstance().rtkStopAllTimer(); - - if (Device.getInstance().isDeviceConnected()) { - ToastUtils.showShort(Rstring.device_has_connected()); - } else { - requestLocationPermission(RC_LOCATION_PERM_CONNECT); - } - } - }; - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(Rmenu.menu_activity_connect_totalstaion(), menu); - if (AppUtils.isAppDebug()) { - menu.findItem(Rid.menu_activity_connect_totalstation_comm_debug()).setVisible(true); - } - return super.onCreateOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int itemId = item.getItemId(); - if (itemId == android.R.id.home) { - finish(); - } else if (itemId == Rid.menu_activity_connect_totalstation_scan()) { - mNewDevicesArrayAdapter.clear(); - requestLocationPermission(RC_LOCATION_PERM_SCAN); - } else if (itemId == Rid.menu_activity_connect_totalstation_disconnect()) { - Device.getInstance().requestDisconnect(); - if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_SPP - || Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_BLE - || Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_QXBT) { - for (int i = 0; i < mPairedDevicesArrayAdapter.getCount(); i++) { - mPairedListView.setItemChecked(i, false); - } - for (int i = 0; i < mNewDevicesArrayAdapter.getCount(); i++) { - mNewDevicesListView.setItemChecked(i, false); - } - } - } else if (itemId == Rid.menu_activity_connect_totalstation_coord_prefix()) { - showCoordPrefixDialog(); - } else if (itemId == Rid.menu_activity_connect_totalstation_comm_debug()) { - startActivity(new Intent(this, ToolCommDebugActivity.class)); - } - return super.onOptionsItemSelected(item); - } - - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - switch (requestCode) { - case REQUEST_ENABLE_BT: - if (resultCode == Activity.RESULT_OK) { - if (currentRequestCode == RC_BLUETOOTH_PERM_SCAN) { - requestBtScanPermission(); - } - } else { - Log.d("ConnectTSActivity", "BT not enabled"); - ToastUtils.showShort(Rstring.bt_not_enabled()); - } - break; - } - if (requestCode == XXPermissions.REQUEST_CODE) { - switch (currentRequestCode) { - case RC_LOCATION_PERM_CONNECT: - if (XXPermissions.isGranted(this, Permission.ACCESS_FINE_LOCATION)) { - requestBtConnectPermission(); - } else { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_connection_requires_positioning_permission_please_turn_it_on_manually); - } - break; - case RC_LOCATION_PERM_SCAN: - if (XXPermissions.isGranted(this, Permission.ACCESS_FINE_LOCATION)) { - requestBtScanPermission(); - } else { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_scan_requires_positioning_permission_please_turn_it_on_manually); - } - break; - case RC_BLUETOOTH_PERM_CONNECT: - if (XXPermissions.isGranted(this, Permission.BLUETOOTH_CONNECT)) { - requestBtConnectPermission(); - } else { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_connection_requires_positioning_permission_please_turn_it_on_manually); - } - break; - case RC_BLUETOOTH_PERM_SCAN: - if (XXPermissions.isGranted(this, Permission.BLUETOOTH_SCAN)) { - requestBtScanPermission(); - } else { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_scan_need_permission); - } - break; - } - } - } - - /** - * 连接蓝牙先请求打开定位权限 - */ - public void requestLocationPermission(int type) { - currentRequestCode = type; - if (XXPermissions.isGranted(this, Permission.ACCESS_FINE_LOCATION)) { - switch (type) { - case RC_LOCATION_PERM_SCAN: - requestBtScanPermission(); - break; - case RC_LOCATION_PERM_CONNECT: - requestBtConnectPermission(); - break; - } - } else { - new MaterialDialog.Builder(this) - .title(Rstring.location_permission()) - .content(Rstring.bluetooth_need_location_permission()) - .canceledOnTouchOutside(false) - .positiveText(Rstring.to_allow()) - .negativeText(Rstring.refuse()) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - XXPermissions.with(ConnectTSActivity.this).permission(Permission.ACCESS_FINE_LOCATION, Permission.ACCESS_COARSE_LOCATION).request(new OnPermissionCallback() { - @Override - public void onGranted(List permissions, boolean all) { - if (all || permissions.contains(Permission.ACCESS_FINE_LOCATION)) { - startService(); - if (updateBluetoothList()) { - ThreadPoolUtil.executeInMain(new Runnable() { - @Override - public void run() { - switch (type) { - case RC_LOCATION_PERM_SCAN: - requestBtScanPermission(); - break; - case RC_LOCATION_PERM_CONNECT: - requestBtConnectPermission(); - break; - } - } - }, 500); - } - } - } - - @Override - public void onDenied(List permissions, boolean never) { - if (never) { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_scan_requires_positioning_permission_please_turn_it_on_manually); - // 如果是被永久拒绝就跳转到应用权限系统设置页面 - XXPermissions.startPermissionActivity(ConnectTSActivity.this, permissions); - } else { - requestLocationPermission(type); - } - } - }); - } - }).onNegative(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_connection_requires_positioning_permission_please_turn_it_on_manually); - } - }).show(); - } - } - - public void requestBtScanPermission() { - currentRequestCode = RC_BLUETOOTH_PERM_SCAN; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - if (XXPermissions.isGranted(this, Permission.BLUETOOTH_SCAN, Permission.BLUETOOTH_CONNECT)) { - doDiscovery(); - } else { - new MaterialDialog.Builder(this) - .title(Rstring.bluetooth_scan_permission()) - .content(Rstring.bluetooth_scan_need_permission()) - .canceledOnTouchOutside(false) - .positiveText(Rstring.to_allow()) - .negativeText(Rstring.refuse()) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) { - XXPermissions.with(ConnectTSActivity.this) - .permission(Permission.BLUETOOTH_SCAN, Permission.BLUETOOTH_CONNECT) - .request(new OnPermissionCallback() { - @Override - public void onGranted(List permissions, boolean all) { - if (all) { - startService(); - if (updateBluetoothList()) { - ThreadPoolUtil.executeInMain(new Runnable() { - @Override - public void run() { - doDiscovery(); - } - }, 500); - } - } else if (!permissions.contains(Permission.BLUETOOTH_SCAN)) { - requestBtScanPermission(); - } else if (!permissions.contains(Permission.BLUETOOTH_CONNECT)) { - requestBtConnectPermission(); - } - } - - @Override - public void onDenied(List permissions, boolean never) { - if (never) { - if (permissions.contains(Permission.BLUETOOTH_SCAN)) { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_connection_requires_positioning_permission_please_turn_it_on_manually); - // 如果是被永久拒绝就跳转到应用权限系统设置页面 - XXPermissions.startPermissionActivity(ConnectTSActivity.this, Permission.BLUETOOTH_SCAN); - } else if (permissions.contains(Permission.BLUETOOTH_CONNECT)) { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_connection_requires_positioning_permission_please_turn_it_on_manually); - // 如果是被永久拒绝就跳转到应用权限系统设置页面 - XXPermissions.startPermissionActivity(ConnectTSActivity.this, Permission.BLUETOOTH_CONNECT); - } - } else { - requestBtScanPermission(); - } - } - }); - } - }) - .onNegative(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - ToastUtils.showShort(com.bingce.device.ui.R.string.bluetooth_connect_need_permission); - } - }) - .show(); - - } - } else { - doDiscovery(); - } - } - - - public void requestBtConnectPermission() { - currentRequestCode = RC_BLUETOOTH_PERM_CONNECT; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - if (XXPermissions.isGranted(this, Permission.BLUETOOTH_CONNECT)) { - connect(); - } else { - new MaterialDialog.Builder(this) - .title(Rstring.bluetooth_connect_permission()) - .content(Rstring.bluetooth_connect_need_permission()) - .canceledOnTouchOutside(false) - .positiveText(Rstring.to_allow()) - .negativeText(Rstring.refuse()) - .onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) { - XXPermissions.with(ConnectTSActivity.this) - .permission(Permission.BLUETOOTH_CONNECT) - .request(new OnPermissionCallback() { - @Override - public void onGranted(List permissions, boolean all) { - startService(); - if (updateBluetoothList()) { - ThreadPoolUtil.executeInMain(new Runnable() { - @Override - public void run() { - connect(); - } - }, 500); - } - } - - @Override - public void onDenied(List permissions, boolean never) { - if (never) { - ToastUtils.showLong(com.bingce.device.ui.R.string.bluetooth_connection_requires_positioning_permission_please_turn_it_on_manually); - // 如果是被永久拒绝就跳转到应用权限系统设置页面 - XXPermissions.startPermissionActivity(ConnectTSActivity.this, Permission.BLUETOOTH_CONNECT); - } else { - requestBtConnectPermission(); - } - } - }); - } - }) - .onNegative(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - ToastUtils.showShort(com.bingce.device.ui.R.string.bluetooth_connect_need_permission); - } - }) - .show(); - } - } else { - connect(); - } - } - - public void connect() { - String checkedInfo; - if (mPairedListView.getCheckedItemPosition() >= 0 && mPairedListView.getCheckedItemPosition() < mPairedDevicesArrayAdapter.getCount()) { - checkedInfo = mPairedDevicesArrayAdapter.getItem(mPairedListView.getCheckedItemPosition()); - } else if (mNewDevicesListView.getCheckedItemPosition() >= 0 && mNewDevicesListView.getCheckedItemPosition() < mNewDevicesArrayAdapter.getCount()) { - checkedInfo = mNewDevicesArrayAdapter.getItem(mNewDevicesListView.getCheckedItemPosition()); - } else { - ToastUtils.showShort(Rstring.please_choose_device_first()); - return; - } - String[] arr = checkedInfo.split("\n", 0); - if (arr.length != 2) { - return; - } - ToastUtils.showShort(Rstring.connecting_please_wait()); - Device.getInstance().deviceBlueName = arr[0]; - Device.getInstance().deviceMacAddress = arr[1]; - Gnss.getInstance().getDevice().getBlue().setScanName(Device.getInstance().deviceBlueName); - Gnss.getInstance().getDevice().getBlue().setScanAddr(Device.getInstance().deviceMacAddress); - Gnss.getInstance().save(); - Device.getInstance().requestConnect(); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ConnectTSActivity.this); - SharedPreferences.Editor editor = prefs.edit(); - editor.putString("deviceBlueName", Device.getInstance().deviceBlueName); - editor.putString("deviceMacAddress", Device.getInstance().deviceMacAddress); - editor.apply(); - } - - public void showCoordPrefixDialog() { - MaterialDialog dialog = new MaterialDialog.Builder(this).title(Rstring.coordinate_prefix()).customView(Rlayout.dialog_coord_prefix(), false).onPositive(new MaterialDialog.SingleButtonCallback() { - @Override - public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { - TsConfig.getInstance().setPrefixX(met_coord_prefix_x.getText().toString().trim()); - TsConfig.getInstance().setPrefixY(met_coord_prefix_y.getText().toString().trim()); - TsConfig.getInstance().setPrefixZ(met_coord_prefix_z.getText().toString().trim()); - TsConfig.getInstance().save(); - SoftKeyUtils.hideSoftKey(); - } - }).positiveText(this.getString(Rstring.save())).negativeText(this.getString(Rstring.cancel())).build(); - - met_coord_prefix_x = dialog.getCustomView().findViewById(Rid.met_dialog_coord_prefix_x()); - met_coord_prefix_y = dialog.getCustomView().findViewById(Rid.met_dialog_coord_prefix_y()); - met_coord_prefix_z = dialog.getCustomView().findViewById(Rid.met_dialog_coord_prefix_z()); - - initMaterialEditTextColor(); - - met_coord_prefix_x.setText(TsConfig.getInstance().getPrefixX()); - met_coord_prefix_y.setText(TsConfig.getInstance().getPrefixY()); - met_coord_prefix_z.setText(TsConfig.getInstance().getPrefixZ()); - - dialog.show(); - } - - @Override - protected void onDestroy() { - super.onDestroy();// 确保我们没有发现,检测设备 - cancelScan(); - // 设置显示进度条 - setProgressBarIndeterminateVisibility(false); - - TsListener.getInstance().removeTsTestListener(this); - - if (publicReceiver != null) unregisterReceiver(publicReceiver); - } - - @SuppressLint("MissingPermission") - private void doDiscovery() { - if (!XXPermissions.isGranted(this, Permission.BLUETOOTH_SCAN)) { - return; - } - // 显示新设备的子标题 - layoutNewDevices.setVisibility(View.VISIBLE); - cancelScan(); - // 如果已经在请求现实了,那么就先停止 - if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_SPP) { - // 请求从蓝牙适配器得到能够被发现的设备 - if (mBtAdapter != null) { - mBtAdapter.startDiscovery(); - } - ToastUtils.showLong(Rstring.scanning()); - } else { - BleScanner.getInstance().scan(null, null, null, false, 30000, new BleScanCallback() { - @Override - public void onScanFinished(List scanResultList) { - ToastUtils.showShort(com.bingce.device.ui.R.string.scan_complete); - } - - @Override - public void onScanStarted(boolean success) { - ToastUtils.showLong(Rstring.scanning()); - } - - @Override - public void onScanning(BleDevice bleDevice) { - if (bleDevice.getName() == null) return; - String itemString = bleDevice.getName() + "\n" + bleDevice.getMac(); -// for (int i = 0; i < mPairedDevicesArrayAdapter.getCount(); i++) { -// if (itemString.equals(mPairedDevicesArrayAdapter.getItem(i))) { -// return; -// } -// } - int count = mNewDevicesArrayAdapter.getCount(); - if (count < 1) {//列表为空时,直接添加,不需要检查是否重复 - mNewDevicesArrayAdapter.add(itemString); - } else {//列表不为空时检查是否重复 - boolean has = false; - for (int j = 0; j < count; j++) { - if (itemString.equals(mNewDevicesArrayAdapter.getItem(j))) { - has = true; - break; - } - } - if (!has) { - mNewDevicesArrayAdapter.add(itemString); - } - } - } - }); - } - } - - /** - * 取消蓝牙扫描 - */ - @SuppressLint("MissingPermission") - private void cancelScan() { - if (!XXPermissions.isGranted(this, Permission.BLUETOOTH_SCAN)) { - return; - } - if (mBtAdapter != null && mBtAdapter.isDiscovering()) { - mBtAdapter.cancelDiscovery(); - } - if (BleManager.getInstance().getScanSate() == BleScanState.STATE_SCANNING) - BleManager.getInstance().cancelScan(); - } - - View.OnClickListener listener = new View.OnClickListener() { - @Override - public void onClick(View v) { - int id = v.getId(); - if (id == Rid.activity_connect_total_station_btn_test()) { - if (Device.getInstance().isDeviceConnected()) { - TotalStation.getInstance().requestTest(); - } else { - ToastUtils.showShort(com.bingce.device.ui.R.string.no_instrument_connected); - } - } -// else if (id == Rid.activity_connect_total_station_btn_guide()) { -// EventBus.getDefault().post(new OpenShortUrlEvent("android_url_ts_communication_guide")); -// } else if (id == Rid.activity_connect_total_station_taobao()) { -// new AlertDialog.Builder(ConnectTSActivity.this) -// .setTitle(Rstring.hint()).setMessage(Rstring.buy_bluetooth_explain()) -// .setPositiveButton(Rstring.buy(), new DialogInterface.OnClickListener() { -// @Override -// public void onClick(DialogInterface dialog, int which) { -// EventBus.getDefault().post(new OpenShortUrlEvent("bluetoothTaobaoUrl")); -// } -// }) -// .setNegativeButton(Rstring.cancel(), null) -// .show(); -// } - } - }; - - class PublicReceiver extends BroadcastReceiver { - @SuppressLint("MissingPermission") - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - // 当发现一个设备时 - if (BluetoothDevice.ACTION_FOUND.equals(action)) { - if (!XXPermissions.isGranted(ConnectTSActivity.this, Permission.BLUETOOTH_CONNECT, Permission.ACCESS_FINE_LOCATION)) { - return; - } - // 从Intent得到蓝牙设备对象 - BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); - // 如果已经配对,则跳过,因为他已经在设备列表中了 - if (device != null && device.getName() != null /*&& device.getBondState() != BluetoothDevice.BOND_BONDED*/) { - // 否则添加到新设备列表 - int count = mNewDevicesArrayAdapter.getCount(); - String itemString = device.getName() + "\n" + device.getAddress(); - if (count < 1) {//列表为空时,直接添加,不需要检查是否重复 - mNewDevicesArrayAdapter.add(itemString); - } else {//列表不为空时检查是否重复 - boolean has = false; - for (int i = 0; i < count; i++) { - if (itemString.equals(mNewDevicesArrayAdapter.getItem(i))) { - has = true; - break; - } - } - if (!has) { - mNewDevicesArrayAdapter.add(itemString); - } - } - } - } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { - // 如果计数为0,则表示没有发现蓝牙 - if (mNewDevicesArrayAdapter.getCount() == 0) { - ToastUtils.showLong(Rstring.none_found()); - } - } - } - } - - private void initMaterialEditTextColor() { - if (Device.getInstance().isThemeDark) { - met_coord_prefix_x.setMetTextColor(Color.WHITE); - met_coord_prefix_y.setMetTextColor(Color.WHITE); - met_coord_prefix_z.setMetTextColor(Color.WHITE); - - met_coord_prefix_x.setPrimaryColor(Color.LTGRAY); - met_coord_prefix_y.setPrimaryColor(Color.LTGRAY); - met_coord_prefix_z.setPrimaryColor(Color.LTGRAY); - - met_coord_prefix_x.setFocusFraction(1.0f); - met_coord_prefix_y.setFocusFraction(1.0f); - met_coord_prefix_z.setFocusFraction(1.0f); - - met_coord_prefix_x.setMetHintTextColor(Color.GRAY); - met_coord_prefix_y.setMetHintTextColor(Color.GRAY); - met_coord_prefix_z.setMetHintTextColor(Color.GRAY); - - met_coord_prefix_x.setUnderlineColor(Color.GRAY); - met_coord_prefix_y.setUnderlineColor(Color.GRAY); - met_coord_prefix_z.setUnderlineColor(Color.GRAY); - } - } - - /** - * 获取热点创建状态 - **/ - public static boolean isWifiApOpen() { - WifiManager wifiManager = (WifiManager) Utils.getApp().getApplicationContext().getSystemService(Context.WIFI_SERVICE); - try { - int i = (Integer) wifiManager.getClass().getMethod("getWifiApState", new Class[0]).invoke(wifiManager, new Object[0]); - return i == WIFI_AP_STATE_ENABLED; - } catch (Exception ignored) { - } - return false; - } - - public static void start() { - Device.getInstance().deviceType = DeviceTypeEnum.DEVICE_TYPE_TS; - ActivityUtils.startActivity(ConnectTSActivity.class); - } - - public static void start(Context context) { - Device.getInstance().deviceType = DeviceTypeEnum.DEVICE_TYPE_TS; - context.startActivity(startIntent(context)); - } - - public static void start(Fragment fragment) { - Device.getInstance().deviceType = DeviceTypeEnum.DEVICE_TYPE_TS; - fragment.startActivity(startIntent(fragment.getActivity())); - } - - private static Intent startIntent(Context context) { - Intent intent500 = new Intent(context, ConnectTSActivity.class); - intent500.putExtra("customChannel", AppChannel.customChannel); - return intent500; - } - - @Override - public void onTsTestSuccess(Coordinate coordinate) { - String instrumentInfo; - if (Device.getInstance().connectType == ConnectTypeEnum.CONNECT_TYPE_HOTSPOT) { - instrumentInfo = "Wifi\n" + "IP:" + TsConfig.getInstance().getIp() + "\n" + getString(Rstring.port()) + ":" + TsConfig.getInstance().getPort() + "\n"; - } else { - instrumentInfo = getString(Rstring.instrument_name()) + ":" + Device.getInstance().deviceBlueName + "\n" + getString(Rstring.instrument_type_name()) + ":" + Device.getInstance().deviceBrand + "\n" + getString(Rstring.comm_delay()) + ":" + TsConfig.getInstance().getCommDelay().getName() + "\n"; - } - StringBuffer buffer = new StringBuffer(); - buffer.append(instrumentInfo); - if (TsConfig.getInstance().getSetupStationMethod().getMode() != SetupStationModeEnum.ON_TOTAL_STATION || !TotalStation.getInstance().isSupportCoordinate()) { - buffer.append(StringUtils.getString(totalstation.Rstring.this_ts_type_need_setup_station_in_totalstation()) + "\n"); - } - if (coordinate != null) { - buffer.append("\nX=" + Util.formatDouble2StringDotAuto(coordinate.getX()) + "\nY=" + Util.formatDouble2StringDotAuto(coordinate.getY()) + "\nZ=" + Util.formatDouble2StringDotAuto(coordinate.getZ()) + "\n"); - } - - if (TotalStation.getInstance() instanceof TopconInterface) { - buffer.append(com.bingce.device.ui.R.string.if_the_coordinates_are_reduced_by_a_factor_of_10_modify_the_decimal_point_setting_of_the_total_station_to_4_digits); - } - new MaterialDialog.Builder(ConnectTSActivity.this) - .title(Rstring.test_result()) - .content(buffer.toString()) - .negativeText(Rstring.close()) - .show(); - } - - @Override - public void onTsTestFailed(String errorMsg, String original) { - new MaterialDialog.Builder(ConnectTSActivity.this) - .title(Rstring.test_result()) - .content(errorMsg + "\n" + original) - .negativeText(Rstring.close()) - .show(); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/project/survey/ui/lofting/LoftingListActivity.kt b/app/src/main/java/com/project/survey/ui/lofting/LoftingListActivity.kt index 54f6dae..80af716 100644 --- a/app/src/main/java/com/project/survey/ui/lofting/LoftingListActivity.kt +++ b/app/src/main/java/com/project/survey/ui/lofting/LoftingListActivity.kt @@ -7,7 +7,6 @@ import com.project.survey.ui.base.BaseBindingActivity import com.project.survey.ui.lofting.adapter.LoftingListAdapter import com.project.survey.ui.lofting.pointlofting.PointStakingActivity import com.project.survey.util.ActivityNavUtil -import com.project.survey.widget.decoration.TransparentDividerDecoration class LoftingListActivity : BaseBindingActivity() { diff --git a/app/src/main/java/com/project/survey/ui/lofting/pointlofting/PointStakingActivity.java b/app/src/main/java/com/project/survey/ui/lofting/pointlofting/PointStakingActivity.java index 9ad25d0..00fd0e1 100644 --- a/app/src/main/java/com/project/survey/ui/lofting/pointlofting/PointStakingActivity.java +++ b/app/src/main/java/com/project/survey/ui/lofting/pointlofting/PointStakingActivity.java @@ -1,12 +1,9 @@ package com.project.survey.ui.lofting.pointlofting; import static com.bingce.surveyor.util.ConstUtils.intentConst.KEY_JOB_ID; -import static com.bingce.surveyor.util.ConstUtils.intentConst.KEY_PROJECT_ID; -import static com.bingce.surveyor.util.ConstUtils.intentConst.KEY_ROAD_ID; -import static com.project.survey.util.DrawableUtils.RADIUS_BOTTOM; -import static com.project.survey.util.DrawableUtils.RADIUS_TOP; import android.annotation.SuppressLint; +import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -75,7 +72,6 @@ import com.project.survey.ui.lofting.pointlofting.record.util.RecordTypeConstant import com.project.survey.ui.pointmeasure.measure.util.SurveyToolBarClickListenerUtils; import com.project.survey.util.CommonUtils; import com.project.survey.util.DeviceConnectUtil; -import com.project.survey.util.DrawableUtils; import com.project.survey.util.SurveyUIUtils; import java.util.ArrayList; @@ -100,6 +96,7 @@ import lecho.hellocharts.renderer.LineChartRenderer; */ public class PointStakingActivity extends BaseSurveyNewActivity { + private Context mContext; private ActivityPointStakingBinding binding; private final Line currentPointLine = new Line(); //实测点 private final Line surveyBasePointLine = new Line();//待放样点(点库的点) @@ -113,18 +110,17 @@ public class PointStakingActivity extends BaseSurveyNewActivity { private PointRecord targetStakePointRecord; private Coordinate currentCoordinate; private Coordinate currentSmoothCoordinate; - protected final CachedCurrentRoadKt cachedRoadKt = new CachedCurrentRoadKt(this); +// protected final CachedCurrentRoadKt cachedRoadKt = new CachedCurrentRoadKt(this); private final SurveyRemarksUtils surveyRemarksUtils = new SurveyRemarksUtils(); private IText distance, moveWestEast, moveSouthNorth, moveDigFill, moveLeftRight, moveBeforeAfter; private MoveValue moveK; private MoveValue moveD; private boolean isTsWatchRecord; - private final TargetCompassHelper targetCompassHelper = new TargetCompassHelper(this, App.magneticDeclination); + private final TargetCompassHelper targetCompassHelper = new TargetCompassHelper(this, ((App) Utils.getApp()).magneticDeclination); private final PointStakingLogic pointStakingLogic = new PointStakingLogic(() -> this); private boolean isTirpsAddSP; private CustomDialog.Builder builder; private String recordRemarks; - private final List stringListLibraty = new ArrayList<>(); private final List methodList = new ArrayList<>(); private SharedPreferences preferences; private boolean isFirstUpdateChartView; @@ -138,43 +134,14 @@ public class PointStakingActivity extends BaseSurveyNewActivity { @Override protected void initView() { + mContext = this; preferences = PreferenceManager.getDefaultSharedPreferences(this); targetCompassHelper.register(angle -> { binding.dirCompass.setAngle(angle); }); - builder = new CustomDialog.Builder(PointStakingActivity.this); + builder = new CustomDialog.Builder(this); initChartView(); - if (App.instance.isThemeDark()) { - binding.layoutPoleHrHeight.tvPoleHrHeight.setTextColor(getColor(R.color.white)); - binding.tvStakingPointName.setTextColor(getColor(R.color.white)); - binding.tvDistance.setTextColor(getColor(R.color.white)); - binding.tvDigFill.setTextColor(getColor(R.color.white)); - binding.tvTopThree.setTextColor(getColor(R.color.white)); - binding.tvTopFour.setTextColor(getColor(R.color.white)); - binding.tvTopFive.setTextColor(getColor(R.color.white)); - binding.tvTopSix.setTextColor(getColor(R.color.white)); - binding.tvLastPoint.setTextColor(getColor(R.color.white)); - binding.tvRecentlyPoint.setTextColor(getColor(R.color.white)); - binding.tvNextPoint.setTextColor(getColor(R.color.white)); - binding.tvScale.setTextColor(getColor(R.color.white)); - - binding.tvTargetCoordinate.setTextColor(getColor(R.color.white)); - binding.tvTargetX.setTextColor(getColor(R.color.white)); - binding.tvTargetY.setTextColor(getColor(R.color.white)); - binding.tvTargetZ.setTextColor(getColor(R.color.white)); - binding.tvMeasuredCoordinate.setTextColor(getColor(R.color.white)); - binding.tvSurveyX.setTextColor(getColor(R.color.white)); - binding.tvSurveyY.setTextColor(getColor(R.color.white)); - binding.tvSurveyZ.setTextColor(getColor(R.color.white)); - - DrawableUtils.tintModifyColorVector(binding.ivLastPoint, R.drawable.icon_triangle_left, R.color.white); - DrawableUtils.tintModifyColorVector(binding.ivNextPoint, R.drawable.icon_triangle_right, R.color.white); - DrawableUtils.tintModifyColorVector(binding.ivScale, R.drawable.ic_scale, R.color.white); - DrawableUtils.setClickBackgroundEffect(binding.topLayout, R.color.theme_dark_black, R.color.theme_dark_black, 10, RADIUS_BOTTOM); - DrawableUtils.setClickBackgroundEffect(binding.bottomLayout, R.color.theme_dark_black, R.color.theme_dark_black, 10, RADIUS_TOP); - } - //比例尺 SurveyToolBarClickListenerUtils.setScaleViewOnClickListener(binding.lineChartView, binding.tvScale, binding.ivScale); //工具栏功能(左上角) @@ -184,7 +151,7 @@ public class PointStakingActivity extends BaseSurveyNewActivity { @Override public void onSettingClickListener() { stopSoundPool(); - PointStakingSettingActivity.start(PointStakingActivity.this); + PointStakingSettingActivity.start(mContext); } @Override @@ -226,40 +193,19 @@ public class PointStakingActivity extends BaseSurveyNewActivity { //点库选点 binding.pointLibrary.setOnClickListener(v -> { if (mStakingPointIsInMemory) return; - CustomRecycleDialog.showDialog(PointStakingActivity.this, R.string.data_source, stringListLibraty, 0, false, (index, itemString) -> { - stopSoundPool(); - switch (index) { - case 0: - //放样点库 - StakingNewJobActivity.pickPoint(PointStakingActivity.this, (pointId, pointsListIndex, name, x, y, z) -> - onPickedPoint(true, pointId, name, x, y, z)); - break; - case 1: - //工程全局控制点 - ControlPointsNewActivity.pickPoint(PointStakingActivity.this, true, (pointId, name, code, x, y, z, remarks) -> { - onPickedPoint(false, pointId, name, x, y, z); - }); - break; - case 2: - //测量点库 - CoordinatePointsLibraryActivity.pickPoint(PointStakingActivity.this, (pointId, name, code, x, y, z, b, l, h) -> { - onPickedPoint(false, pointId, name, x, y, z); - }); - break; - } - }); + StakingNewJobActivity.pickPoint(this, (pointId, pointsListIndex, name, x, y, z) -> + onPickedPoint(true, pointId, name, x, y, z)); }); - //移动方法 showTopMoveMethod(); binding.tvMoveMethod.setOnClickListener(v -> { methodList.clear(); - methodList.add(getString(R.string.k_d)); +// methodList.add(getString(R.string.k_d)); if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS) { methodList.add(getString(R.string.before_after_left_right)); } methodList.add(getString(R.string.east_west_north_south)); - CustomRecycleDialog.showDialog(PointStakingActivity.this, R.string.move_method, methodList, + CustomRecycleDialog.showDialog(this, R.string.move_method, methodList, Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS ? PreferencesUtil.getMoveMethodTypeTS() : PreferencesUtil.getMoveMethodTypeRTK(), false, (index, itemString) -> { if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS) { @@ -277,7 +223,7 @@ public class PointStakingActivity extends BaseSurveyNewActivity { //放样记录 binding.tvStakingRecord.setOnClickListener(v -> { stopSoundPool(); - RecordsActivity.start(PointStakingActivity.this, RecordTypeConstants.TYPE_POINT_STAKE); + RecordsActivity.start(this, RecordTypeConstants.TYPE_POINT_STAKE); }); //仅观测 binding.layoutDragButton.drWatchSurvey.setOnClickListener(v -> watchSurvey()); @@ -348,7 +294,7 @@ public class PointStakingActivity extends BaseSurveyNewActivity { List lineChartDataList = new ArrayList<>(); LineChartData lineBasePointChartData = new LineChartData(); - int blackPointColor = App.instance.isThemeDark() ? getColor(R.color.color_E2E1DD) : getColor(R.color.color_575757); + int blackPointColor = ((App) Utils.getApp()).isThemeDark() ? getColor(R.color.color_E2E1DD) : getColor(R.color.color_575757); int greenPointColor = getColor(R.color.theme_green); int redPointColor = getColor(R.color.color_FF1515); int lightGreenPointColor = getColor(R.color.theme_green_press); @@ -393,7 +339,7 @@ public class PointStakingActivity extends BaseSurveyNewActivity { } String content = getString(R.string.whether_staking_selected_point) + getString(R.string.colon) + stakingLibraryPointList.get(pointIndex).name + "\n" + "X" + getString(R.string.colon) + Util.formatDouble2Double(stakingLibraryPointList.get(pointIndex).x, 6) + " " - + "Y" + getString(R.string.colon) + Util.formatDouble2Double(stakingLibraryPointList.get(pointIndex).y, 6) + "\n" + + "Y" + getString(R.string.colon) + Util.formatDouble2Double(stakingLibraryPointList.get(pointIndex).y, 6)+ "\n" + "Z" + getString(R.string.colon) + Util.formatDouble2Double(stakingLibraryPointList.get(pointIndex).h, 6); builder.setContent(content).setButtonConfirm(v -> { targetStakePointRecord = stakingLibraryPointList.get(pointIndex); @@ -411,47 +357,6 @@ public class PointStakingActivity extends BaseSurveyNewActivity { @Override protected void initData() { - stringListLibraty.add(getString(R.string.staking_point_library)); - stringListLibraty.add(getString(R.string.global_control_point)); - stringListLibraty.add(getString(R.string.point_survey_point_library)); - -// PointDb.getInstance().rawQueryListLiveData(PointConstants.findKnownPointByJob(jobId())).observe(this, pointRecords -> { -// surveyBasePointLine.getValues().clear(); -// stakingPointLine.getValues().clear(); -// recordPointLine.getValues().clear(); -// effectGuideLine.getValues().clear(); -// stakingLibraryPointList.clear(); -// stakingLibraryPointList.addAll(pointRecords); -// for (int i = 0; i < stakingLibraryPointList.size(); i++) { -// PointRecord pointRecord = stakingLibraryPointList.get(i); -// surveyBasePointLine.getValues().add(new PointValue(pointRecord.y, pointRecord.x).setLabel(pointRecord.name)); -// } -// if (stakingLibraryPointList.size() > 0) { -// targetStakePointRecord = stakingLibraryPointList.get(0); -// stakingPointLine.getValues().add(new PointValue(targetStakePointRecord.y, targetStakePointRecord.x).setLabel(targetStakePointRecord.name)); -// updateBottomInfo(targetStakePointRecord.name, targetStakePointRecord.x, targetStakePointRecord.y, targetStakePointRecord.h); -// drawRecordPointLine(); -// if (currentCoordinate != null) { -// drawCurrentPointLine(currentCoordinate.getX(), currentCoordinate.getY(), currentCoordinate.getZ()); -// updateTopInfo(currentCoordinate); -// } else { -// showTopMoveMethod(); -// } -// isTirpsAddSP = false; -// } else { -// targetStakePointRecord = null; -// binding.tvStakingPointName.setText(getString(R.string.staking_point_name)); -// binding.tvTargetX.setText(TextFactory.fixedString("X")); -// binding.tvTargetY.setText(TextFactory.fixedString("Y")); -// binding.tvTargetZ.setText(TextFactory.fixedString("Z")); -// showTopMoveMethod(); -// isTirpsAddSP = true; -// } -// ((LineChartRenderer) binding.lineChartView.getChartRenderer()).calculateMaxViewport(1.5f); -// binding.lineChartView.onChartDataChange(); -// binding.lineChartView.setCurrentViewport(binding.lineChartView.getMaximumViewport()); -// }); - String targetPointList = IntentUtil.stringExtra(this, KEY_POINT_LIST); if (StringUtil.isEmpty(targetPointList)) { PointDb.getInstance().rawQueryListLiveData(PointConstants.findKnownPointByJob(jobId())).observe(this, pointRecords -> { @@ -538,7 +443,7 @@ public class PointStakingActivity extends BaseSurveyNewActivity { ToastUtils.showShort(getString(R.string.add_points_staking_point_first)); return; } - SurveyLimitCheckUtils.checkStakingLimit(PointStakingActivity.this, currentCoordinate, new Coordinate(targetStakePointRecord.x, targetStakePointRecord.y), (currentCoordinate, targetCoordinate) -> recordPoint()); + SurveyLimitCheckUtils.checkStakingLimit(this, currentCoordinate, new Coordinate(targetStakePointRecord.x, targetStakePointRecord.y), (currentCoordinate, targetCoordinate) -> recordPoint()); } else { tsMeasCoordinateManager.measureCoordinate(); } @@ -553,14 +458,14 @@ public class PointStakingActivity extends BaseSurveyNewActivity { lineChartViewBuilder.setButtonConfirmTextColor(R.color.color_E2E1DD); lineChartViewBuilder.setButtonConfirm(v -> { - SurveyLimitCheckUtils.checkStakingLimit(PointStakingActivity.this, currentSmoothCoordinate, new Coordinate(targetStakePointRecord.x, targetStakePointRecord.y), (currentCoordinate, targetCoordinate) -> recordPoint()); + SurveyLimitCheckUtils.checkStakingLimit(this, currentSmoothCoordinate, new Coordinate(targetStakePointRecord.x, targetStakePointRecord.y), (currentCoordinate, targetCoordinate) -> recordPoint()); }); // lineChartViewBuilder.setButtonConfirm(v -> checkRtkStringLimit()); customDialog = lineChartViewBuilder.create(); customDialog.show(); isControlSurvey = true; } else { - SurveyLimitCheckUtils.checkStakingLimit(PointStakingActivity.this, currentCoordinate, new Coordinate(targetStakePointRecord.x, targetStakePointRecord.y), (currentCoordinate, targetCoordinate) -> recordPoint()); + SurveyLimitCheckUtils.checkStakingLimit(this, currentCoordinate, new Coordinate(targetStakePointRecord.x, targetStakePointRecord.y), (currentCoordinate, targetCoordinate) -> recordPoint()); } } } @@ -711,6 +616,16 @@ public class PointStakingActivity extends BaseSurveyNewActivity { clearRefreshReset(); } + /** + * 接收 RTK 返回的数据 + * @param antennaHeight + * @param blh + * @param originalBlh + * @param coordinate + * @param hdop + * @param vdop + * @param pdop + */ @Override public void onRtkPositionReceived(double antennaHeight, Blh blh, Blh originalBlh, Coordinate coordinate, double hdop, double vdop, double pdop) { super.onRtkPositionReceived(antennaHeight, blh, originalBlh, coordinate, hdop, vdop, pdop); @@ -862,7 +777,7 @@ public class PointStakingActivity extends BaseSurveyNewActivity { if (targetStakePointRecord == null) { if (isTirpsAddSP) { builder.setContent(getString(R.string.add_points_staking_point_first)).setButtonConfirm(v -> { - StakingNewJobActivity.start(PointStakingActivity.this); + StakingNewJobActivity.start(this); }).create().show(); isTirpsAddSP = false; } @@ -879,11 +794,11 @@ public class PointStakingActivity extends BaseSurveyNewActivity { } } - if (!cachedRoadKt.isDataReady()) { - return; - } +// if (!cachedRoadKt.isDataReady()) { +// return; +// } - PointStakingLogic.Result result = pointStakingLogic.calculate(cachedRoadKt.roadEditor(), + PointStakingLogic.Result result = pointStakingLogic.calculate(null, new PointStakingLogic.Configs(6, moveType), new PointStakingLogic.Parameter( new MeasuredPoint(currentCoordinate.getX(), currentCoordinate.getY(), currentCoordinate.getZ(), currentCoordinate.getName()), @@ -934,8 +849,8 @@ public class PointStakingActivity extends BaseSurveyNewActivity { while (display_station_angle >= Math.PI * 2) display_station_angle -= Math.PI * 2; double measured_angle = CoordUtil.calcAzimuth(TsConfig.getInstance().getStation(), currentCoordinate); - binding.tvTopFive.setText(getString(R.string.station_angle) + getString(R.string.colon) + Util.radianToDmsString(display_station_angle, 6)); - binding.tvTopSix.setText(getString(R.string.station_angle_diff) + getString(R.string.colon) + Util.radianToDmsString(station_angle - measured_angle, 6, false)); + binding.tvTopFive.setText(getString(R.string.station_angle) + getString(R.string.colon) + Util.radianToDmsString(display_station_angle, ((App) Utils.getApp()).angleNotNumber())); + binding.tvTopSix.setText(getString(R.string.station_angle_diff) + getString(R.string.colon) + Util.radianToDmsString(station_angle - measured_angle, ((App) Utils.getApp()).angleNotNumber(), false)); } else { switch (PreferencesUtil.getMoveMethodTypeRTK()) { case 0: @@ -968,12 +883,12 @@ public class PointStakingActivity extends BaseSurveyNewActivity { double foreBackMoveValue = moveDistance.getX(); moveBeforeAfter = foreBackMoveValue >= 0 - ? TextFactory.distanceFormatDouble2String(getString(R.string.to_before), Math.abs(foreBackMoveValue), 6) - : TextFactory.distanceFormatDouble2String(getString(R.string.to_after), Math.abs(foreBackMoveValue), 6); + ? TextFactory.distanceFormatDouble2String("向前", Math.abs(foreBackMoveValue), 6) + : TextFactory.distanceFormatDouble2String("向后", Math.abs(foreBackMoveValue), 6); binding.tvTopThree.setText(foreBackMoveValue >= 0 - ? TextFactory.distanceFormatDouble2String(getString(R.string.to_before) + getString(R.string.colon), Math.abs(foreBackMoveValue), 6) - : TextFactory.distanceFormatDouble2String(getString(R.string.to_after) + getString(R.string.colon), Math.abs(foreBackMoveValue), 6)); + ? TextFactory.distanceFormatDouble2String("向前" + getString(R.string.colon), Math.abs(foreBackMoveValue), 6) + : TextFactory.distanceFormatDouble2String("向后" + getString(R.string.colon), Math.abs(foreBackMoveValue), 6)); double leftRightValue = moveDistance.getY(); moveLeftRight = leftRightValue >= 0 @@ -991,7 +906,7 @@ public class PointStakingActivity extends BaseSurveyNewActivity { : TextFactory.distanceFormatDouble2String(getString(R.string.to_east), targetStakePointRecord.y - currentCoordinate.getY(), 6); moveSouthNorth = currentCoordinate.getX() > targetStakePointRecord.x - ? TextFactory.distanceFormatDouble2String(getString(R.string.to_south), currentCoordinate.getX() - targetStakePointRecord.x,6) + ? TextFactory.distanceFormatDouble2String(getString(R.string.to_south), currentCoordinate.getX() - targetStakePointRecord.x, 6) : TextFactory.distanceFormatDouble2String(getString(R.string.to_north), targetStakePointRecord.x - currentCoordinate.getX(), 6); binding.tvTopThree.setText(currentCoordinate.getY() > targetStakePointRecord.y @@ -1127,12 +1042,12 @@ public class PointStakingActivity extends BaseSurveyNewActivity { DeviceUtils.StationData stationData = DeviceUtils.stationData( new BasePoint(targetStakePointRecord.x, targetStakePointRecord.y, targetStakePointRecord.h), - 6, + ((App) Utils.getApp()).angleNotNumber(), 6); DeviceInfoData deviceInfoData = DeviceUtils.collectDeviceInfo(); PointStakeRecord pointStakeRecord = new PointStakeRecord(projectId, jobId, roadId, targetStakePointRecord.id, moveBeforeAfter != null ? moveBeforeAfter.getString() : "", moveLeftRight != null ? moveLeftRight.getString() : "", moveWestEast != null ? moveWestEast.getString() : "", moveSouthNorth != null ? moveSouthNorth.getString() : "", - cachedRoadKt.road().getName() + "" , targetStakePointRecord.name , Util.formatDouble2StringDotAuto(targetStakePointRecord.x) , Util.formatDouble2StringDotAuto(targetStakePointRecord.y) @@ -1169,34 +1084,34 @@ public class PointStakingActivity extends BaseSurveyNewActivity { */ private void showTopMoveMethod() { binding.tvDistance.setText(getString(R.string.distance)); - binding.tvDigFill.setText(getString(R.string.dig_fill)); + binding.tvDigFill.setText("填挖"); if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS) { switch (PreferencesUtil.getMoveMethodTypeTS()) { +// case 0: +// binding.tvTopThree.setText(getString(R.string.k)); +// binding.tvTopFour.setText(getString(R.string.d)); +// break; case 0: - binding.tvTopThree.setText(getString(R.string.k)); - binding.tvTopFour.setText(getString(R.string.d)); - break; - case 1: - binding.tvTopThree.setText(getString(R.string.to_before)); + binding.tvTopThree.setText("向前"); binding.tvTopFour.setText(getString(R.string.to_left)); break; - case 2: + case 1: binding.tvTopThree.setText(getString(R.string.to_north)); binding.tvTopFour.setText(getString(R.string.to_east)); break; } binding.topFiveSixLayout.setVisibility(View.VISIBLE); } else { - switch (PreferencesUtil.getMoveMethodTypeRTK()) { - case 0: - binding.tvTopThree.setText(getString(R.string.k)); - binding.tvTopFour.setText(getString(R.string.d)); - break; - case 1: +// switch (PreferencesUtil.getMoveMethodTypeRTK()) { +// case 0: +// binding.tvTopThree.setText(getString(R.string.k)); +// binding.tvTopFour.setText(getString(R.string.d)); +// break; +// case 1: binding.tvTopThree.setText(getString(R.string.to_north)); binding.tvTopFour.setText(getString(R.string.to_east)); - break; - } +// break; +// } binding.topFiveSixLayout.setVisibility(View.GONE); } binding.tvTopFive.setText(getString(R.string.station_angle)); @@ -1217,9 +1132,22 @@ public class PointStakingActivity extends BaseSurveyNewActivity { return IntentUtil.stringExtra(getIntent(), KEY_JOB_ID); } - private static final String KEY_POINT_LIST = "key_point_list"; + public static void start(Activity activity) { + ThreadPoolUtil.execute(() -> { + String projectId = CachedProject.currentProjectId(); + String roadId = CachedCurrentRoad.currentRoadId(projectId); + String jobId = CachedCurrentJob.currentJobId(projectId); + Intent intent = new Intent(activity, PointStakingActivity.class); + intent.putExtra(KEY_JOB_ID, jobId); +// intent.putExtra(KEY_PROJECT_ID, projectId); +// intent.putExtra(KEY_ROAD_ID, roadId); + activity.startActivity(intent); + }); + } + private static final String KEY_POINT_LIST = "key_point_list"; + public static void start(Context context, List stakingPointList) { Gson gson = new Gson(); Intent intent = new Intent(context, PointStakingActivity.class); @@ -1227,19 +1155,6 @@ public class PointStakingActivity extends BaseSurveyNewActivity { context.startActivity(intent); } - public static void start(Context context) { - ThreadPoolUtil.execute(() -> { - String projectId = CachedProject.currentProjectId(); - String roadId = CachedCurrentRoad.currentRoadId(projectId); - String jobId = CachedCurrentJob.currentJobId(projectId); - Intent intent = new Intent(context, PointStakingActivity.class); - intent.putExtra(KEY_JOB_ID, jobId); - intent.putExtra(KEY_PROJECT_ID, projectId); - intent.putExtra(KEY_ROAD_ID, roadId); - context.startActivity(intent); - }); - } - @Override protected void onDestroy() { super.onDestroy(); @@ -1261,4 +1176,9 @@ public class PointStakingActivity extends BaseSurveyNewActivity { binding.baseSurveyStakingSetting.tvTiltPrimAuto.setTextColor(getColor(R.color.color_BCBCBC)); } } + +// @Override +// public boolean isUseSystemStyleNavigationBar() { +// return true; +// } } \ No newline at end of file diff --git a/app/src/main/java/com/project/survey/ui/lofting/pointlofting/PointStakingActivity1.java b/app/src/main/java/com/project/survey/ui/lofting/pointlofting/PointStakingActivity1.java new file mode 100644 index 0000000..fdb3e9e --- /dev/null +++ b/app/src/main/java/com/project/survey/ui/lofting/pointlofting/PointStakingActivity1.java @@ -0,0 +1,1211 @@ +package com.project.survey.ui.lofting.pointlofting; + +import static com.bingce.surveyor.util.ConstUtils.intentConst.KEY_JOB_ID; +import static com.bingce.surveyor.util.ConstUtils.intentConst.KEY_PROJECT_ID; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.graphics.DashPathEffect; +import android.text.TextUtils; +import android.view.View; + +import androidx.preference.PreferenceManager; +import androidx.sqlite.db.SimpleSQLiteQuery; + +import com.bingce.autounit.IText; +import com.bingce.autounit.TextFactory; +import com.bingce.chart.ChartViewUtils; +import com.bingce.coordlib.model.Blh; +import com.bingce.coordlib.model.Coordinate; +import com.bingce.coordlib.util.CoordUtil; +import com.bingce.data.DeviceInfoData; +import com.bingce.data.cache.CachedCurrentJob; +import com.bingce.data.cache.CachedCurrentRoad; +import com.bingce.data.cache.CachedProject; +import com.bingce.data.database.DBQueryConstant; +import com.bingce.data.database.PointDb; +import com.bingce.data.database.PointStakeDb; +import com.bingce.data.surveyor.surveydata.pointstake.PointStakeConstants; +import com.bingce.data.surveyor.surveydata.pointstake.PointStakeRecord; +import com.bingce.data.surveyor.surveydata.pointsurvey.PointConstants; +import com.bingce.data.surveyor.surveydata.pointsurvey.PointRecord; +import com.bingce.device.Device; +import com.bingce.device.enums.DeviceTypeEnum; +import com.bingce.device.util.DeviceUtils; +import com.bingce.logic.PointStakingLogic; +import com.bingce.logic.bean.MeasuredPoint; +import com.bingce.logic.bean.MoveValue; +import com.bingce.logic.bean.StakingPoint; +import com.bingce.logic.linestaking.TargetCompassHelper; +import com.bingce.road.move.MoveK; +import com.bingce.road.move.MoveLeftRight; +import com.bingce.surveyor.agentweb.HelpWebActivity; +import com.bingce.surveyor.util.ConstUtils; +import com.bingce.surveyor.util.PreferencesUtil; +import com.bingce.surveyor.util.SurveyLimitCheckUtils; +import com.bingce.surveyor.util.SurveyRemarksUtils; +import com.bingce.surveyor.util.dialog.CustomDialog; +import com.bingce.surveyor.util.dialog.CustomRecycleDialog; +import com.bingce.totalstation.TotalStation; +import com.bingce.totalstation.TsConfig; +import com.bingce.utils.IntentUtil; +import com.bingce.utils.PointUtils; +import com.bingce.utils.SoundPoolUtil; +import com.bingce.utils.StringUtil; +import com.bingce.utils.ThreadPoolUtil; +import com.bingce.utils.Util; +import com.project.survey.App; +import com.project.survey.R; +import com.project.survey.databinding.ActivityPointStakingBinding; +import com.project.survey.dialog.CustomInputListDialog; +import com.project.survey.dialog.CustomLineChartDialog; +import com.project.survey.model.ControlRecord; +import com.project.survey.ui.base.BaseSurveyNewActivity; +import com.project.survey.ui.instrument.setupstation.StakingNewJobActivity; +import com.project.survey.ui.lofting.pointlofting.record.RecordsActivity; +import com.project.survey.ui.lofting.pointlofting.record.util.RecordTypeConstants; +import com.project.survey.ui.pointmeasure.measure.util.SurveyToolBarClickListenerUtils; +import com.project.survey.util.CommonUtils; +import com.project.survey.util.DeviceConnectUtil; +import com.project.survey.util.SurveyUIUtils; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import blankj.utilcode.util.ToastUtils; +import cn.liuyanbing.surveyor.model.base.BasePoint; +import cn.liuyanbing.surveyor.model.util.CUtil; +import google.gson.Gson; +import google.gson.reflect.TypeToken; +import lecho.hellocharts.listener.LineChartOnValueSelectListener; +import lecho.hellocharts.model.Line; +import lecho.hellocharts.model.LineChartData; +import lecho.hellocharts.model.PointValue; +import lecho.hellocharts.renderer.LineChartRenderer; + + +/** + * 点放样 测量 + */ +public class PointStakingActivity1 extends BaseSurveyNewActivity { + + private Context mContext; + private ActivityPointStakingBinding binding; + private final Line currentPointLine = new Line(); //实测点 + private final Line surveyBasePointLine = new Line();//待放样点(点库的点) + private final Line stakingPointLine = new Line(); //放样点 + private final Line recordPointLine = new Line(); //记录点 + private final Line effectGuideLine = new Line(); //放样引导线 + private final Line effectHorLine = new Line(); //放样提示横向虚线 + private final Line effectVerLine = new Line(); //放样提示纵向虚线 + private final List stakingLibraryPointList = new ArrayList<>(); + private List recordStakingBasePointList; + private PointRecord targetStakePointRecord; + private Coordinate currentCoordinate; + private Coordinate currentSmoothCoordinate; +// protected final CachedCurrentRoadKt cachedRoadKt = new CachedCurrentRoadKt(this); + private final SurveyRemarksUtils surveyRemarksUtils = new SurveyRemarksUtils(); + private IText distance, moveWestEast, moveSouthNorth, moveDigFill, moveLeftRight, moveBeforeAfter; + private MoveValue moveK; + private MoveValue moveD; + private boolean isTsWatchRecord; + private final TargetCompassHelper targetCompassHelper = new TargetCompassHelper(this, App.magneticDeclination); + private final PointStakingLogic pointStakingLogic = new PointStakingLogic(() -> this); + private boolean isTirpsAddSP; + private CustomDialog.Builder builder; + private String recordRemarks; +// private final List stringListLibraty = new ArrayList<>(); + private final List methodList = new ArrayList<>(); + private SharedPreferences preferences; + private boolean isFirstUpdateChartView; + private boolean mStakingPointIsInMemory = false; + + @Override + public View getContentView() { + binding = ActivityPointStakingBinding.inflate(getLayoutInflater()); + return binding.getRoot(); + } + + @Override + protected void initView() { + mContext = this; + preferences = PreferenceManager.getDefaultSharedPreferences(this); + targetCompassHelper.register(angle -> { + binding.dirCompass.setAngle(angle); + }); + builder = new CustomDialog.Builder(mContext); + initChartView(); + + //比例尺 + SurveyToolBarClickListenerUtils.setScaleViewOnClickListener(binding.lineChartView, binding.tvScale, binding.ivScale); + //工具栏功能(左上角) + SurveyToolBarClickListenerUtils.setOnClickListener(this, true, true, + baseSurveyActivityUtils.activityBaseSurveyBinding, + binding.baseSurveyStakingSetting, new SurveyToolBarClickListenerUtils.IToolBarClickListener() { + @Override + public void onSettingClickListener() { + stopSoundPool(); + PointStakingSettingActivity.start(mContext); + } + + @Override + public void onPositionCenterClickListener() { + if (currentCoordinate == null) { + ToastUtils.showShort(getString(R.string.please_observe_measure_first)); + return; + } + binding.lineChartView.setZoomLevel(currentCoordinate.getY(), currentCoordinate.getX(), binding.lineChartView.getZoomLevel()); + binding.lineChartView.moveToWithAnimation(currentCoordinate.getY(), currentCoordinate.getX()); + } + + @Override + public void onFullScreenClickListener() { + ChartViewUtils.centerInScreen(binding.lineChartView); + } + + @Override + public void onAutoPrimsClickListener() { + //自动全站仪寻点 + if (!TotalStation.getInstance().isSupportMotor()) { + ToastUtils.showShort(getString(R.string.device_not_support_auto_search_point)); + return; + } + if (targetStakePointRecord == null) { + ToastUtils.showShort(getString(R.string.please_input_staking_target_point)); + return; + } + Coordinate target; + if (CUtil.isEqual(targetStakePointRecord.h, 0)) { + target = new Coordinate(targetStakePointRecord.x, targetStakePointRecord.y, TsConfig.getInstance().getStationZ()); + } else { + target = new Coordinate(targetStakePointRecord.x, targetStakePointRecord.y, targetStakePointRecord.h); + } + ToastUtils.showShort(getString(R.string.start_auto_find_point)); + TotalStation.getInstance().requestMotorTurnToTarget(target, TsConfig.getInstance().getHr(), false); + } + }); + //点库选点 + binding.pointLibrary.setOnClickListener(v -> { + if (mStakingPointIsInMemory) return; + //放样点库 + StakingNewJobActivity.pickPoint(PointStakingActivity1.this, (pointId, pointsListIndex, name, x, y, z) -> + onPickedPoint(true, pointId, name, x, y, z)); + }); + + //移动方法 + showTopMoveMethod(); + binding.tvMoveMethod.setOnClickListener(v -> { + methodList.clear(); +// methodList.add(getString(R.string.k_d)); + if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS) { + methodList.add(getString(R.string.before_after_left_right)); + } + methodList.add(getString(R.string.east_west_north_south)); + CustomRecycleDialog.showDialog(mContext, R.string.move_method, methodList, + Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS ? PreferencesUtil.getMoveMethodTypeTS() + : PreferencesUtil.getMoveMethodTypeRTK(), false, (index, itemString) -> { + if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS) { + PreferencesUtil.putPreference(ConstUtils.preferConst.moveMethodTypeTS, index); + } else { + PreferencesUtil.putPreference(ConstUtils.preferConst.moveMethodTypeRTK, index); + } + if (currentCoordinate != null && targetStakePointRecord != null) { + updateTopInfo(currentCoordinate); + } else { + showTopMoveMethod(); + } + }); + }); + //放样记录/采集记录 + binding.tvStakingRecord.setOnClickListener(v -> { + stopSoundPool(); + RecordsActivity.start(mContext, RecordTypeConstants.TYPE_POINT_STAKE); + }); + //仅观测 + binding.layoutDragButton.drWatchSurvey.setOnClickListener(v -> watchSurvey()); + //观测并记录 + binding.layoutDragButton.drWatchSurveyRecord.setOnClickListener(v -> watchSurveyRecord()); + //长按保存 + binding.layoutDragButton.drWatchSurveyRecord.setTouchOnLongClickListener(() -> + SurveyRemarksUtils.createRecordRemarks(this, recordRemarks, remarks -> + recordRemarks = remarks + ) + ); + //上一点 + binding.llLastPoint.setOnClickListener(v -> { + onLastOrNextPoint(true); + }); + //最近点 + binding.llRecentlyPoint.setOnClickListener(v -> { + onRecentlyPoint(); + }); + //下一点 + binding.llNextPoint.setOnClickListener(v -> { + onLastOrNextPoint(false); + }); + + //输入实测点 + binding.baseSurveyStakingSetting.rlInputCurrentPoint.setOnClickListener(v -> { + if (Device.getInstance().isDeviceConnected() && Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_RTK) { + ToastUtils.showShort(getString(R.string.disconnect_device_use_input_point)); + return; + } + String inputSurveyX = currentCoordinate != null ? Util.formatDouble2String(currentCoordinate.getX(), 4) : ""; + String inputSurveyY = currentCoordinate != null ? Util.formatDouble2String(currentCoordinate.getY(), 4) : ""; + String inputSurveyZ = currentCoordinate != null ? Util.formatDouble2String(currentCoordinate.getZ(), 4) : ""; + new CustomInputListDialog.Builder(this).setTitle(getString(R.string.input_current_point)) + .setInputHint01("X") + .setInputHint02("Y") + .setInputHint03("Z") + .setInputText01(inputSurveyX).setInputText02(inputSurveyY).setInputText03(inputSurveyZ) + .setInputFormat(CustomInputListDialog.Builder.INPUT_TYPE_PM_DECIMAL) + .setButtonConfirm((editText01, editText02, editText03) -> { + if (TextUtils.isEmpty(editText01) || TextUtils.isEmpty(editText02) || TextUtils.isEmpty(editText03)) { + ToastUtils.showShort(getString(R.string.please_input_full_coordinate_parameters)); + return; + } + binding.baseSurveyStakingSetting.ivPositionCenter.setImageResource(R.drawable.icon_survey_position_center_black); + currentCoordinate = new Coordinate(Double.parseDouble(editText01), Double.parseDouble(editText02), Double.parseDouble(editText03)); + updatePosition(); + }).create().show(); + }); + } + + @Override + protected void onResume() { + super.onResume(); + //左侧工具栏的状态显示 + SurveyUIUtils.updatePoleHrHeightDraggingToolBarLayout( + this, true, + binding.layoutPoleHrHeight, binding.layoutDragButton, binding.baseSurveyStakingSetting, + true, true, currentCoordinate); + if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS) { + binding.topFiveSixLayout.setVisibility(View.VISIBLE); + } else { + binding.topFiveSixLayout.setVisibility(View.GONE); + } + } + + private void initChartView() { + + List lineChartDataList = new ArrayList<>(); + LineChartData lineBasePointChartData = new LineChartData(); + int blackPointColor = App.instance.isThemeDark() ? getColor(R.color.color_E2E1DD) : getColor(R.color.color_575757); + int greenPointColor = getColor(R.color.theme_green); + int redPointColor = getColor(R.color.color_FF1515); + int lightGreenPointColor = getColor(R.color.theme_green_press); + int redLineColor = getColor(R.color.color_FF1515); + int pointRadius = 3; + int strokeWidth = 1; + int effectLineWidth = 6; + + surveyBasePointLine.setCubic(false).setHasLabels(true).setHasPoints(true).setStrokeWidth(strokeWidth).setHasLines(false).setPointRadius(pointRadius).setPointColor(blackPointColor).setShowLabelBackground(false).setLabelTextColor(blackPointColor); + stakingPointLine.setCubic(false).setHasLabels(true).setHasPoints(true).setStrokeWidth(strokeWidth).setHasLines(false).setPointRadius(pointRadius).setPointColor(greenPointColor).setShowLabelBackground(false).setLabelTextColor(greenPointColor); + currentPointLine.setCubic(false).setHasLabels(true).setHasPoints(true).setStrokeWidth(strokeWidth).setHasLines(false).setPointRadius(pointRadius).setPointColor(redPointColor).setShowLabelBackground(false).setLabelTextColor(redPointColor); + recordPointLine.setCubic(false).setHasLabels(true).setHasPoints(true).setStrokeWidth(strokeWidth).setHasLines(false).setPointRadius(pointRadius).setPointColor(lightGreenPointColor).setShowLabelBackground(false).setLabelTextColor(lightGreenPointColor); + effectGuideLine.setCubic(false).setStrokeWidth(strokeWidth).setPointRadius(0).setColor(redLineColor).setPathEffect(new DashPathEffect(new float[]{effectLineWidth, effectLineWidth}, 0)); + effectHorLine.setCubic(false).setStrokeWidth(strokeWidth).setPointRadius(0).setColor(blackPointColor).setPathEffect(new DashPathEffect(new float[]{effectLineWidth, effectLineWidth}, 0)); + effectVerLine.setCubic(false).setStrokeWidth(strokeWidth).setPointRadius(0).setColor(blackPointColor).setPathEffect(new DashPathEffect(new float[]{effectLineWidth, effectLineWidth}, 0)); + + //lineBasePointChartData添加一下line的顺序勿随意改动,此顺序涉及到lineChartView图选点功能 + lineBasePointChartData.getLines().add(currentPointLine); + lineBasePointChartData.getLines().add(surveyBasePointLine); + lineBasePointChartData.getLines().add(stakingPointLine); + lineBasePointChartData.getLines().add(recordPointLine); + lineBasePointChartData.getLines().add(effectGuideLine); + lineBasePointChartData.getLines().add(effectHorLine); + lineBasePointChartData.getLines().add(effectVerLine); + lineChartDataList.add(lineBasePointChartData); + + CommonUtils.mChartViewSetLineChartDatas(binding.lineChartView, lineChartDataList, false, false); + if (binding.lineChartView.getChartRenderer() instanceof LineChartRenderer) { + ((LineChartRenderer) binding.lineChartView.getChartRenderer()).calculateMaxViewport(1.5f); + } + + binding.lineChartView.setMaxZoom(1000); + binding.lineChartView.setViewportCalculationEnabled(false); + binding.lineChartView.setCurrentViewport(binding.lineChartView.getMaximumViewport()); + + binding.lineChartView.setOnValueTouchListener(new LineChartOnValueSelectListener() { + @Override + public void onValueSelected(int lineIndex, int pointIndex, PointValue value) { + if (lineIndex == 1) {//代表选中的点属于surveyBasePointLine + if (pointIndex > stakingLibraryPointList.size() - 1) { + return; + } + String content = getString(R.string.whether_staking_selected_point) + getString(R.string.colon) + stakingLibraryPointList.get(pointIndex).name + "\n" + + "X" + getString(R.string.colon) + Util.formatDouble2Double(stakingLibraryPointList.get(pointIndex).x, 6) + " " + + "Y" + getString(R.string.colon) + Util.formatDouble2Double(stakingLibraryPointList.get(pointIndex).y, 6) + "\n" + + "Z" + getString(R.string.colon) + Util.formatDouble2Double(stakingLibraryPointList.get(pointIndex).h, 6); + builder.setContent(content).setButtonConfirm(v -> { + targetStakePointRecord = stakingLibraryPointList.get(pointIndex); + updateUI(); + }).create().show(); + } + } + + @Override + public void onValueDeselected() { + + } + }); + } + + @Override + protected void initData() { +// stringListLibraty.add(getString(R.string.staking_point_library)); +// stringListLibraty.add(getString(R.string.global_control_point)); +// stringListLibraty.add(getString(R.string.point_survey_point_library)); + +// PointDb.getInstance().rawQueryListLiveData(PointConstants.findKnownPointByJob(jobId())).observe(this, pointRecords -> { +// surveyBasePointLine.getValues().clear(); +// stakingPointLine.getValues().clear(); +// recordPointLine.getValues().clear(); +// effectGuideLine.getValues().clear(); +// stakingLibraryPointList.clear(); +// stakingLibraryPointList.addAll(pointRecords); +// for (int i = 0; i < stakingLibraryPointList.size(); i++) { +// PointRecord pointRecord = stakingLibraryPointList.get(i); +// surveyBasePointLine.getValues().add(new PointValue(pointRecord.y, pointRecord.x).setLabel(pointRecord.name)); +// } +// if (stakingLibraryPointList.size() > 0) { +// targetStakePointRecord = stakingLibraryPointList.get(0); +// stakingPointLine.getValues().add(new PointValue(targetStakePointRecord.y, targetStakePointRecord.x).setLabel(targetStakePointRecord.name)); +// updateBottomInfo(targetStakePointRecord.name, targetStakePointRecord.x, targetStakePointRecord.y, targetStakePointRecord.h); +// drawRecordPointLine(); +// if (currentCoordinate != null) { +// drawCurrentPointLine(currentCoordinate.getX(), currentCoordinate.getY(), currentCoordinate.getZ()); +// updateTopInfo(currentCoordinate); +// } else { +// showTopMoveMethod(); +// } +// isTirpsAddSP = false; +// } else { +// targetStakePointRecord = null; +// binding.tvStakingPointName.setText(getString(R.string.staking_point_name)); +// binding.tvTargetX.setText(TextFactory.fixedString("X")); +// binding.tvTargetY.setText(TextFactory.fixedString("Y")); +// binding.tvTargetZ.setText(TextFactory.fixedString("Z")); +// showTopMoveMethod(); +// isTirpsAddSP = true; +// } +// ((LineChartRenderer) binding.lineChartView.getChartRenderer()).calculateMaxViewport(1.5f); +// binding.lineChartView.onChartDataChange(); +// binding.lineChartView.setCurrentViewport(binding.lineChartView.getMaximumViewport()); +// }); + + String targetPointList = IntentUtil.stringExtra(this, KEY_POINT_LIST); + if (StringUtil.isEmpty(targetPointList)) { + PointDb.getInstance().rawQueryListLiveData(PointConstants.findKnownPointByJob(jobId())).observe(this, pointRecords -> { + onPointRecordsUpdate(pointRecords); + }); + } else { + mStakingPointIsInMemory = true; + Gson gson = new Gson(); + List points = gson.fromJson(targetPointList, new TypeToken>() { + }.getType()); + List pointRecords = new ArrayList<>(); + for (StakingPoint point : points) { + pointRecords.add(new PointRecord( + "", "", "", + point.getCategory(), + point.getName(), + "", + "", + point.getX(), point.getY(), point.getZ(), + 0, 0, 0, PointConstants.POINT_FORMAT_XYZ, new DeviceInfoData())); + } + onPointRecordsUpdate(pointRecords); + } + } + + private void onPointRecordsUpdate(List pointRecords) { + surveyBasePointLine.getValues().clear(); + stakingPointLine.getValues().clear(); + recordPointLine.getValues().clear(); + effectGuideLine.getValues().clear(); + stakingLibraryPointList.clear(); + stakingLibraryPointList.addAll(pointRecords); + for (int i = 0; i < stakingLibraryPointList.size(); i++) { + PointRecord pointRecord = stakingLibraryPointList.get(i); + surveyBasePointLine.getValues().add(new PointValue(pointRecord.y, pointRecord.x).setLabel(pointRecord.name)); + } + if (stakingLibraryPointList.size() > 0) { + targetStakePointRecord = stakingLibraryPointList.get(0); + stakingPointLine.getValues().add(new PointValue(targetStakePointRecord.y, targetStakePointRecord.x).setLabel(targetStakePointRecord.name)); + updateBottomInfo(targetStakePointRecord.name, targetStakePointRecord.x, targetStakePointRecord.y, targetStakePointRecord.h); + drawRecordPointLine(); + if (currentCoordinate != null) { + drawCurrentPointLine(currentCoordinate.getX(), currentCoordinate.getY(), currentCoordinate.getZ()); + updateTopInfo(currentCoordinate); + } else { + showTopMoveMethod(); + } + isTirpsAddSP = false; + } else { + targetStakePointRecord = null; + binding.tvStakingPointName.setText(getString(R.string.staking_point_name)); + binding.tvTargetX.setText(TextFactory.fixedString("X")); + binding.tvTargetY.setText(TextFactory.fixedString("Y")); + binding.tvTargetZ.setText(TextFactory.fixedString("Z")); + showTopMoveMethod(); + isTirpsAddSP = true; + } + ((LineChartRenderer) binding.lineChartView.getChartRenderer()).calculateMaxViewport(1.5f); + binding.lineChartView.onChartDataChange(); + binding.lineChartView.setCurrentViewport(binding.lineChartView.getMaximumViewport()); + } + + private void watchSurvey() { + if (DeviceConnectUtil.isDeviceConnectSelectDialog(this, baseSurveyActivityUtils.activityBaseSurveyBinding)) { + if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS) { + isTsWatchRecord = false; + tsMeasCoordinateManager.measureCoordinate(); + } else { + ToastUtils.showShort(getString(R.string.not_support_function_observation_only)); + } + } + } + + private CustomLineChartDialog.Builder lineChartViewBuilder; + private CustomLineChartDialog customDialog; + private boolean isControlSurvey; + + /** + * 观测并记录 + */ + private void watchSurveyRecord() { + if (DeviceConnectUtil.isDeviceConnectSelectDialog(this, baseSurveyActivityUtils.activityBaseSurveyBinding)) { + if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS) { + isTsWatchRecord = true; + if (currentCoordinate != null) { + if (targetStakePointRecord == null) { + ToastUtils.showShort(getString(R.string.add_points_staking_point_first)); + return; + } + SurveyLimitCheckUtils.checkStakingLimit(mContext, currentCoordinate, new Coordinate(targetStakePointRecord.x, targetStakePointRecord.y), (currentCoordinate, targetCoordinate) -> recordPoint()); + } else { + tsMeasCoordinateManager.measureCoordinate(); + } + } else { + if (targetStakePointRecord == null) { + ToastUtils.showShort(getString(R.string.add_points_staking_point_first)); + return; + } + boolean isSmoothStaking = PreferencesUtil.getPreferenceInt(ConstUtils.preferConst.rtkStakingSmoothPointsNumber, 1) != 1; + if (isSmoothStaking) { + lineChartViewBuilder = new CustomLineChartDialog.Builder(this).setTitle(getString(R.string.staking_points_being_collected)); + lineChartViewBuilder.setButtonConfirmTextColor(R.color.color_E2E1DD); + lineChartViewBuilder.setButtonConfirm(v -> { + + SurveyLimitCheckUtils.checkStakingLimit(mContext, currentSmoothCoordinate, new Coordinate(targetStakePointRecord.x, targetStakePointRecord.y), (currentCoordinate, targetCoordinate) -> recordPoint()); + }); +// lineChartViewBuilder.setButtonConfirm(v -> checkRtkStringLimit()); + customDialog = lineChartViewBuilder.create(); + customDialog.show(); + isControlSurvey = true; + } else { + SurveyLimitCheckUtils.checkStakingLimit(mContext, currentCoordinate, new Coordinate(targetStakePointRecord.x, targetStakePointRecord.y), (currentCoordinate, targetCoordinate) -> recordPoint()); + } + } + } + } + + @Override + protected void performMeasure() { + watchSurvey(); + } + + @Override + protected void performMeasureRecord() { + watchSurveyRecord(); + } + + @Override + protected void performLast() { + onLastOrNextPoint(true); + } + + @Override + protected void performNext() { + onLastOrNextPoint(false); + } + + @Override + protected void performRecord() { + binding.layoutDragButton.drWatchSurveyRecord.performClick(); + } + + private void onRecentlyPoint() { + if (currentCoordinate == null) { + ToastUtils.showShort(getString(R.string.return_coordinate_empty_check_device)); + return; + } + if (targetStakePointRecord == null) { + ToastUtils.showShort(getString(R.string.add_points_staking_point_first)); + return; + } + if (stakingLibraryPointList.size() > 0) { + stakingLibraryPointList.size(); + double minDistance = PointUtils.getDistance2D(new BasePoint(stakingLibraryPointList.get(0).x, stakingLibraryPointList.get(0).y), new BasePoint(currentCoordinate.getX(), currentCoordinate.getY())); + targetStakePointRecord = stakingLibraryPointList.get(0); + for (int i = 1; i < stakingLibraryPointList.size(); i++) { + double distance2D = PointUtils.getDistance2D(new BasePoint(stakingLibraryPointList.get(i).x, stakingLibraryPointList.get(i).y), new BasePoint(currentCoordinate.getX(), currentCoordinate.getY())); + if (minDistance > distance2D) { + targetStakePointRecord = stakingLibraryPointList.get(i); + minDistance = distance2D; + } + } + ToastUtils.showShort(targetStakePointRecord.name + " " + getString(R.string.is_current_recently_point)); + updateUI(); + } + } + + private void onLastOrNextPoint(boolean nextOrLast) { + if (targetStakePointRecord == null) { + ToastUtils.showShort(getString(R.string.add_points_staking_point_first)); + return; + } + if (mStakingPointIsInMemory) { + int currentIndex = -1; + for (int i = 0; i < stakingLibraryPointList.size(); i++) { + if (stakingLibraryPointList.get(i) == targetStakePointRecord) { + currentIndex = i; + break; + } + } + if (currentIndex == -1) { + return; + } + currentIndex += stakingLibraryPointList.size(); + int targetIndex = (nextOrLast ? currentIndex + 1 : currentIndex - 1) % stakingLibraryPointList.size(); + targetStakePointRecord = stakingLibraryPointList.get(targetIndex); + updateUI(); + return; + } + ThreadPoolUtil.execute(() -> { + String projectId = CachedProject.currentProjectId(); + String jobId = CachedCurrentJob.currentJobId(projectId); + PointRecord pointRecord = PointDb.getInstance().rawQueryData(PointConstants.findLastNextKnownPointByJobAndDate(jobId, targetStakePointRecord.createDate, nextOrLast)); + runOnUiThread(() -> { + if (pointRecord == null) { + ToastUtils.showShort(nextOrLast ? getString(R.string.the_first_staking_point_list) : getString(R.string.the_last_staking_point_list)); + return; + } + targetStakePointRecord = pointRecord; + + updateUI(); + }); + }); + } + + /** + * 点库返回选择的点 + */ + private void onPickedPoint(boolean isStakingLibPoint, String pointId, String name, double x, double y, double z) { +// if (!isStakingLibPoint) { +// DeviceInfoData deviceInfoData = DeviceUtils.collectDeviceInfo(); +// PointRecord tempStakePointRecord = new PointRecord(pointId, "", "", +// PointConstants.POINT_TYPE_SURVEY_CONTROL_POINT, name, "", "", +// x, y, z, 0, 0, 0, PointConstants.POINT_FORMAT_XYZ, deviceInfoData); +// stakingLibraryPointList.add(tempStakePointRecord); +// targetStakePointRecord = tempStakePointRecord; +// surveyBasePointLine.getValues().add(new PointValue(tempStakePointRecord.y, tempStakePointRecord.x).setLabel(tempStakePointRecord.name)); +// updateUI(); +// } else { + ThreadPoolUtil.execute(() -> { + PointRecord knowPointRecord = PointDb.getInstance().rawQueryData(PointConstants.findKnownPointById(pointId)); + runOnUiThread(() -> { + targetStakePointRecord = knowPointRecord; + updateUI(); + }); + }); +// } + } + + private void updateUI() { + if (targetStakePointRecord == null) { + return; + } + stakingPointLine.getValues().clear(); + stakingPointLine.getValues().add(new PointValue(targetStakePointRecord.y, targetStakePointRecord.x).setLabel(targetStakePointRecord.name)); + updateBottomInfo(targetStakePointRecord.name, targetStakePointRecord.x, targetStakePointRecord.y, targetStakePointRecord.h); + if (currentCoordinate == null) { + ((LineChartRenderer) binding.lineChartView.getChartRenderer()).calculateMaxViewport(1.5f); + binding.lineChartView.onChartDataChange(); + return; + } + effectGuideLine.getValues().clear(); + if (currentCoordinate != null) { + effectGuideLine.getValues().add(new PointValue(targetStakePointRecord.y, targetStakePointRecord.x)); + effectGuideLine.getValues().add(new PointValue(currentCoordinate.getY(), currentCoordinate.getX())); + updateTopInfo(currentCoordinate); + } + + ((LineChartRenderer) binding.lineChartView.getChartRenderer()).calculateMaxViewport(1.5f); + binding.lineChartView.onChartDataChange(); + drawRecordPointLine(); + } + + private double controlX, controlY, controlZ; + private double controlLat, controlLon, controlAlt; + + @Override + public void onDeviceConnectLost() { + super.onDeviceConnectLost(); + clearRefreshReset(); + } + + @Override + public void onRtkPositionReceived(double antennaHeight, Blh blh, Blh originalBlh, Coordinate coordinate, double hdop, double vdop, double pdop) { + super.onRtkPositionReceived(antennaHeight, blh, originalBlh, coordinate, hdop, vdop, pdop); + currentCoordinate = coordinate; + updatePosition(); + if (isControlSurvey) { + if (lineChartViewBuilder.pointList.size() < (PreferencesUtil.getPreferenceInt(ConstUtils.preferConst.rtkStakingSmoothPointsNumber, 1))) { + lineChartViewBuilder.addDrawBlackSurveyPoint(coordinate, blh); + } else { + double control_all_x = 0; + double control_all_y = 0; + double control_all_z = 0; + double control_all_lat = 0; + double control_all_lon = 0; + double control_all_alt = 0; + for (int i = 0; i < lineChartViewBuilder.pointList.size(); i++) { + control_all_x += lineChartViewBuilder.pointList.get(i).getX(); + control_all_y += lineChartViewBuilder.pointList.get(i).getY(); + control_all_z += lineChartViewBuilder.pointList.get(i).getZ(); + control_all_lat += lineChartViewBuilder.pointList.get(i).getLatitude(); + control_all_lon += lineChartViewBuilder.pointList.get(i).getLongitude(); + control_all_alt += lineChartViewBuilder.pointList.get(i).getAltitude(); + } + + int sNum = PreferencesUtil.getPreferenceInt(ConstUtils.preferConst.rtkStakingSmoothPointsNumber, 1); + + controlX = control_all_x / sNum; + controlY = control_all_y / sNum; + controlZ = control_all_z / sNum; + controlLat = control_all_lat / sNum; + controlLon = control_all_lon / sNum; + controlAlt = control_all_alt / sNum; + currentSmoothCoordinate = new Coordinate(controlX, controlY, controlZ); + lineChartViewBuilder.addDrawRedSurvryPoint(new ControlRecord(controlX, controlY, controlZ, controlLat, controlLon, controlAlt, getString(R.string.setting_point))); + lineChartViewBuilder.pointList.add(0, new ControlRecord(controlX, controlY, controlZ, controlLat, controlLon, controlAlt, getString(R.string.setting_point))); + + isControlSurvey = false; + + lineChartViewBuilder.setButtonConfirmTextColor(R.color.color_575757); + } + } + } + + @Override + public void onMeasCoordinateSuccess(Coordinate coordinate) { + super.onMeasCoordinateSuccess(coordinate); + currentCoordinate = coordinate; + updatePosition(); + if (isTsWatchRecord) { + if (targetStakePointRecord == null) { + ToastUtils.showShort(getString(R.string.add_points_staking_point_first)); + return; + } +// if (lineChartViewBuilder.pointList.size() < (PreferencesUtil.getPreferenceInt(ConstUtils.preferConst.rtkStakingSmoothPointsNumber, 1))) { +// lineChartViewBuilder.addDrawBlackSurveyPoint(new Coordinate(x,y,z), new Blh()); +// } else { +// double control_all_x = 0; +// double control_all_y = 0; +// double control_all_z = 0; +//// double control_all_lat = 0; +//// double control_all_lon = 0; +//// double control_all_alt = 0; +// for (int i = 0; i < lineChartViewBuilder.pointList.size(); i++) { +// control_all_x += lineChartViewBuilder.pointList.get(i).getX(); +// control_all_y += lineChartViewBuilder.pointList.get(i).getY(); +// control_all_z += lineChartViewBuilder.pointList.get(i).getZ(); +//// control_all_lat += lineChartViewBuilder.pointList.get(i).getLatitude(); +//// control_all_lon += lineChartViewBuilder.pointList.get(i).getLongitude(); +//// control_all_alt += lineChartViewBuilder.pointList.get(i).getAltitude(); +// } +// +// int sNum = PreferencesUtil.getPreferenceInt(ConstUtils.preferConst.rtkStakingSmoothPointsNumber, 1); +// +// controlX = control_all_x / sNum; +// controlY = control_all_y / sNum; +// controlZ = control_all_z / sNum; +//// controlLat = control_all_lat / sNum; +//// controlLon = control_all_lon / sNum; +//// controlAlt = control_all_alt / sNum; +// currentSmoothCoordinate = new Coordinate(controlX,controlY,controlZ); +// lineChartViewBuilder.addDrawRedSurvryPoint(new ControlRecord(controlX, controlY, controlZ, 0, 0, 0, getString(R.string.setting_point))); +// lineChartViewBuilder.pointList.add(0, new ControlRecord(controlX, controlY, controlZ, 0, 0, 0, getString(R.string.setting_point))); +// +// isTsWatchRecord = false; +// +// lineChartViewBuilder.setButtonConfirmTextColor(R.color.color_575757); +// } + SurveyLimitCheckUtils.checkStakingLimit(this, currentCoordinate, new Coordinate(targetStakePointRecord.x, targetStakePointRecord.y), (currentCoordinate, targetCoordinate) -> recordPoint()); + } + } + + private void clearRefreshReset() { + + currentCoordinate = null; + + showTopMoveMethod(); + + binding.tvTargetX.setText(TextFactory.fixedString("X")); + binding.tvTargetY.setText(TextFactory.fixedString("Y")); + binding.tvTargetZ.setText(TextFactory.fixedString("Z")); + + binding.tvSurveyX.setText(TextFactory.fixedString("X")); + binding.tvSurveyY.setText(TextFactory.fixedString("Y")); + binding.tvSurveyZ.setText(TextFactory.fixedString("Z")); + + if (currentPointLine != null) { + currentPointLine.getValues().clear(); + } + if (effectGuideLine != null) { + effectGuideLine.getValues().clear(); + } + if (effectHorLine != null) { + effectHorLine.getValues().clear(); + } + if (effectVerLine != null) { + effectVerLine.getValues().clear(); + } + ((LineChartRenderer) binding.lineChartView.getChartRenderer()).calculateMaxViewport(1.5f); + binding.lineChartView.onChartDataChange(); + } + + /** + * 更新坐实测点坐标信息 + */ + private void updatePosition() { + if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS && currentCoordinate == null) { + ToastUtils.showShort(getString(R.string.return_coordinate_empty_check_device)); + return; + } + double x = currentCoordinate.getX(); + double y = currentCoordinate.getY(); + double z = currentCoordinate.getZ(); + drawCurrentPointLine(x, y, z); + updateBottomInfo(x, y, z); + updateTopInfo(new Coordinate(x, y, z)); + } + + + /** + * 更新顶部信息 + */ + @SuppressLint("SetTextI18n") + private void updateTopInfo(Coordinate currentCoordinate) { + if (currentCoordinate == null) { + ToastUtils.showShort(getString(R.string.return_coordinate_empty_check_device)); + return; + } + + if (targetStakePointRecord == null) { + if (isTirpsAddSP) { + builder.setContent(getString(R.string.add_points_staking_point_first)).setButtonConfirm(v -> { + StakingNewJobActivity.start(mContext); + }).create().show(); + isTirpsAddSP = false; + } + return; + } + + ThreadPoolUtil.execute(() -> { + int moveType = 0; + if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS) { + moveType = PreferencesUtil.getMoveMethodTypeTS(); + } else { + if (PreferencesUtil.getMoveMethodTypeRTK() == 1) { + moveType = 2; + } + } + +// if (!cachedRoadKt.isDataReady()) { +// return; +// } + + PointStakingLogic.Result result = pointStakingLogic.calculate(null, + new PointStakingLogic.Configs(6, moveType), + new PointStakingLogic.Parameter( + new MeasuredPoint(currentCoordinate.getX(), currentCoordinate.getY(), currentCoordinate.getZ(), currentCoordinate.getName()), + new StakingPoint(targetStakePointRecord.name, -1, "", targetStakePointRecord.x, targetStakePointRecord.y, targetStakePointRecord.h), + CommonUtils.toBasePoint(TsConfig.getInstance().getStation())) + ); + runOnUiThread(() -> { + if (result == null) { + return; + } + + moveK = null; + moveD = null; + moveWestEast = null; + moveSouthNorth = null; + moveBeforeAfter = null; + moveLeftRight = null; + + targetCompassHelper.updateTargetAzimuth(result.targetAzimuth); + + distance = TextFactory.distanceFormatDouble2String(getString(R.string.distance) + getString(R.string.colon), PointUtils.getDistance2D(new BasePoint(targetStakePointRecord.x, targetStakePointRecord.y, targetStakePointRecord.h), new BasePoint(currentCoordinate.getX(), currentCoordinate.getY(), currentCoordinate.getZ())), 6); + binding.tvDistance.setText(distance); + + moveDigFill = currentCoordinate.getZ() > targetStakePointRecord.h + ? TextFactory.distanceFormatDouble2String(getString(R.string.down_dig), currentCoordinate.getZ() - targetStakePointRecord.h, 6) + : TextFactory.distanceFormatDouble2String(getString(R.string.up_fill), targetStakePointRecord.h - currentCoordinate.getZ(), 6); + binding.tvDigFill.setText(currentCoordinate.getZ() > targetStakePointRecord.h + ? TextFactory.distanceFormatDouble2String(getString(R.string.down_dig) + getString(R.string.colon), currentCoordinate.getZ() - targetStakePointRecord.h, 6) + : TextFactory.distanceFormatDouble2String(getString(R.string.up_fill) + getString(R.string.colon), targetStakePointRecord.h - currentCoordinate.getZ(), 6)); + + if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS) { + switch (PreferencesUtil.getMoveMethodTypeTS()) { + case 0: + moveKD(result); + break; + case 1: + moveForeBack(); + break; + case 2: + moveWestEast(); + break; + } + binding.topFiveSixLayout.setVisibility(View.VISIBLE); + double station_angle = PointUtils.getDirectionDegrees(CommonUtils.toBasePoint(TsConfig.getInstance().getStation()), new BasePoint(targetStakePointRecord.x, targetStakePointRecord.y, targetStakePointRecord.h)); + double display_station_angle = station_angle + TsConfig.getInstance().getAngleDifference(); + while (display_station_angle < 0) + display_station_angle += Math.PI * 2; + while (display_station_angle >= Math.PI * 2) + display_station_angle -= Math.PI * 2; + double measured_angle = CoordUtil.calcAzimuth(TsConfig.getInstance().getStation(), currentCoordinate); + binding.tvTopFive.setText(getString(R.string.station_angle) + getString(R.string.colon) + Util.radianToDmsString(display_station_angle, 6)); + binding.tvTopSix.setText(getString(R.string.station_angle_diff) + getString(R.string.colon) + Util.radianToDmsString(station_angle - measured_angle, 6, false)); + } else { + switch (PreferencesUtil.getMoveMethodTypeRTK()) { + case 0: + moveKD(result); + break; + case 1: + moveWestEast(); + break; + } + binding.topFiveSixLayout.setVisibility(View.GONE); + binding.tvTopFive.setText(getString(R.string.station_angle)); + binding.tvTopSix.setText(getString(R.string.station_angle_diff)); + } + }); + }); + } + + private void moveKD(PointStakingLogic.Result result) { + moveK = result.kMove; + moveD = result.dMove; + + binding.tvTopThree.setText(moveK != null && moveK.value != null ? moveK.value : TextFactory.fixedString("")); + binding.tvTopFour.setText(moveD != null && moveD.value != null ? moveD.value : TextFactory.fixedString("")); + } + + private void moveForeBack() { + BasePoint moveDistance = Util.moveDistance(CommonUtils.toBasePoint(TsConfig.getInstance().getStation()), + new BasePoint(targetStakePointRecord.x, targetStakePointRecord.y, targetStakePointRecord.h) + , new BasePoint(currentCoordinate.getX(), currentCoordinate.getY(), currentCoordinate.getZ())); + + double foreBackMoveValue = moveDistance.getX(); + moveBeforeAfter = foreBackMoveValue >= 0 + ? TextFactory.distanceFormatDouble2String(getString(R.string.to_before), Math.abs(foreBackMoveValue), 6) + : TextFactory.distanceFormatDouble2String(getString(R.string.to_after), Math.abs(foreBackMoveValue), 6); + + binding.tvTopThree.setText(foreBackMoveValue >= 0 + ? TextFactory.distanceFormatDouble2String(getString(R.string.to_before) + getString(R.string.colon), Math.abs(foreBackMoveValue), 6) + : TextFactory.distanceFormatDouble2String(getString(R.string.to_after) + getString(R.string.colon), Math.abs(foreBackMoveValue), 6)); + + double leftRightValue = moveDistance.getY(); + moveLeftRight = leftRightValue >= 0 + ? TextFactory.distanceFormatDouble2String(getString(R.string.to_right), Math.abs(leftRightValue), 6) + : TextFactory.distanceFormatDouble2String(getString(R.string.to_left), Math.abs(leftRightValue), 6); + + binding.tvTopFour.setText(leftRightValue >= 0 + ? TextFactory.distanceFormatDouble2String(getString(R.string.to_right) + getString(R.string.colon), Math.abs(leftRightValue), 6) + : TextFactory.distanceFormatDouble2String(getString(R.string.to_left) + getString(R.string.colon), Math.abs(leftRightValue), 6)); + } + + private void moveWestEast() { + moveWestEast = currentCoordinate.getY() > targetStakePointRecord.y + ? TextFactory.distanceFormatDouble2String(getString(R.string.to_west), currentCoordinate.getY() - targetStakePointRecord.y, 6) + : TextFactory.distanceFormatDouble2String(getString(R.string.to_east), targetStakePointRecord.y - currentCoordinate.getY(), 6); + + moveSouthNorth = currentCoordinate.getX() > targetStakePointRecord.x + ? TextFactory.distanceFormatDouble2String(getString(R.string.to_south), currentCoordinate.getX() - targetStakePointRecord.x,6) + : TextFactory.distanceFormatDouble2String(getString(R.string.to_north), targetStakePointRecord.x - currentCoordinate.getX(), 6); + + binding.tvTopThree.setText(currentCoordinate.getY() > targetStakePointRecord.y + ? TextFactory.distanceFormatDouble2String(getString(R.string.to_west) + getString(R.string.colon), currentCoordinate.getY() - targetStakePointRecord.y, 6) + : TextFactory.distanceFormatDouble2String(getString(R.string.to_east) + getString(R.string.colon), targetStakePointRecord.y - currentCoordinate.getY(), 6)); + + binding.tvTopFour.setText(currentCoordinate.getX() > targetStakePointRecord.x + ? TextFactory.distanceFormatDouble2String(getString(R.string.to_south) + getString(R.string.colon), currentCoordinate.getX() - targetStakePointRecord.x, 6) + : TextFactory.distanceFormatDouble2String(getString(R.string.to_north) + getString(R.string.colon), targetStakePointRecord.x - currentCoordinate.getX(), 6)); + } + + /** + * 更新底部信息 + */ + private void updateBottomInfo(double x, double y, double z) { + updateBottomInfo("", x, y, z); + } + + @SuppressLint("SetTextI18n") + private void updateBottomInfo(String stakingName, double x, double y, double z) { + if (!TextUtils.isEmpty(stakingName)) { + binding.tvStakingPointName.setText(getString(R.string.staking_point_name) + getString(R.string.colon) + stakingName); + binding.tvTargetX.setText(TextFactory.distanceFormatDouble2String("X" + getString(R.string.colon), x, 6)); + binding.tvTargetY.setText(TextFactory.distanceFormatDouble2String("Y" + getString(R.string.colon), y, 6)); + binding.tvTargetZ.setText(TextFactory.distanceFormatDouble2String("Z" + getString(R.string.colon), z, 6)); + } else { + binding.tvSurveyX.setText(TextFactory.distanceFormatDouble2String("X" + getString(R.string.colon), x, 6)); + binding.tvSurveyY.setText(TextFactory.distanceFormatDouble2String("Y" + getString(R.string.colon), y, 6)); + binding.tvSurveyZ.setText(TextFactory.distanceFormatDouble2String("Z" + getString(R.string.colon), z, 6)); + } + } + + /** + * 画红色实测点和虚线引导线 + * + * @param x + * @param y + * @param z + */ + private void drawCurrentPointLine(double x, double y, double z) { + if (currentPointLine.getValues().isEmpty() && surveyBasePointLine.getValues().isEmpty() + && stakingPointLine.getValues().isEmpty() && recordPointLine.getValues().isEmpty() + && effectGuideLine.getValues().isEmpty() && effectHorLine.getValues().isEmpty() + && effectVerLine.getValues().isEmpty()) { + isFirstUpdateChartView = !isFirstUpdateChartView; + } + if (currentPointLine != null) { + currentPointLine.getValues().clear(); + currentPointLine.getValues().add(new PointValue(y, x).setLabel(getString(R.string.measured_point))); + } + if (effectGuideLine != null) { + effectGuideLine.getValues().clear(); + } + if (effectHorLine != null) { + effectHorLine.getValues().clear(); + } + if (effectVerLine != null) { + effectVerLine.getValues().clear(); + } + if (targetStakePointRecord != null && effectGuideLine != null) { + effectGuideLine.getValues().add(new PointValue(y, x)); + effectGuideLine.getValues().add(new PointValue(targetStakePointRecord.y, targetStakePointRecord.x)); + + double distance2D = Util.formatDouble2Double(PointUtils.getDistance2D(new BasePoint(targetStakePointRecord.x, targetStakePointRecord.y), new BasePoint(x, y)), 6); + + double disTipsRange2D = Double.parseDouble(PreferencesUtil.getPointStakingTipsRangeLimit()); + if (distance2D <= disTipsRange2D) { + if (effectHorLine != null && effectVerLine != null) { + effectHorLine.getValues().add(new PointValue((y - disTipsRange2D), x)); + effectHorLine.getValues().add(new PointValue((y + disTipsRange2D), x)); + effectVerLine.getValues().add(new PointValue(y, (x - disTipsRange2D))); + effectVerLine.getValues().add(new PointValue(y, (x + disTipsRange2D))); + } + if (preferences.getBoolean("key_is_tts_open", true)) { + SoundPoolUtil.getInstance().play(SoundPoolUtil.ALPHA_STAKING); + } + } else { + stopSoundPool(); + } + } + if (isFirstUpdateChartView) { + ChartViewUtils.centerInScreen(binding.lineChartView); + isFirstUpdateChartView = !isFirstUpdateChartView; + } + ((LineChartRenderer) binding.lineChartView.getChartRenderer()).calculateMaxViewport(1.5f); + binding.lineChartView.onChartDataChange(); + } + + private void drawRecordPointLine() { + if (targetStakePointRecord == null) { + return; + } + ThreadPoolUtil.execute(() -> { + recordStakingBasePointList = PointStakeDb.getInstance().rawQueryListData(new SimpleSQLiteQuery("SELECT * FROM " + PointStakeConstants.DB_NAME + " WHERE " + DBQueryConstant.NOT_DELETED + DBQueryConstant.AND + " (pointId='" + targetStakePointRecord.id + "')")); + runOnUiThread(() -> { + if (recordPointLine != null) { + recordPointLine.getValues().clear(); + for (int i = 0; i < recordStakingBasePointList.size(); i++) { + PointStakeRecord pointStakeRecord = recordStakingBasePointList.get(i); + recordPointLine.getValues().add(new PointValue(pointStakeRecord.measuredY, pointStakeRecord.measuredX).setLabel("")); + } + } + ((LineChartRenderer) binding.lineChartView.getChartRenderer()).calculateMaxViewport(1.5f); + binding.lineChartView.onChartDataChange(); + }); + }); + } + + /** + * 记录保存放样记录点 + */ + private void recordPoint() { + if (currentCoordinate == null) { + ToastUtils.showShort(getString(R.string.return_coordinate_empty_check_device)); + return; + } + if (targetStakePointRecord == null) { + ToastUtils.showShort(getString(R.string.add_points_staking_point_first)); + return; + } + boolean needCurrentSmoothCoordinate = Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_RTK && PreferencesUtil.getPreferenceInt(ConstUtils.preferConst.rtkStakingSmoothPointsNumber, 1) != 1; + if (needCurrentSmoothCoordinate) { + if (currentSmoothCoordinate == null) { + ToastUtils.showShort(getString(R.string.return_coordinate_empty_check_device)); + return; + } + } + + ThreadPoolUtil.execute(() -> { + String projectId = CachedProject.currentProjectId(); + String jobId = CachedCurrentJob.currentJobId(projectId); +// String roadId = CachedCurrentRoad.currentRoadId(projectId); + + DeviceUtils.StationData stationData = DeviceUtils.stationData( + new BasePoint(targetStakePointRecord.x, targetStakePointRecord.y, targetStakePointRecord.h), + 6, + 6); + DeviceInfoData deviceInfoData = DeviceUtils.collectDeviceInfo(); + PointStakeRecord pointStakeRecord = new PointStakeRecord(projectId, jobId, "", + targetStakePointRecord.id, moveBeforeAfter != null ? moveBeforeAfter.getString() : "", moveLeftRight != null ? moveLeftRight.getString() : "", moveWestEast != null ? moveWestEast.getString() : "", moveSouthNorth != null ? moveSouthNorth.getString() : "", + "" + , targetStakePointRecord.name + , Util.formatDouble2StringDotAuto(targetStakePointRecord.x) + , Util.formatDouble2StringDotAuto(targetStakePointRecord.y) + , Util.formatDouble2StringDotAuto(targetStakePointRecord.h) + , Util.formatDouble2StringDotAuto(needCurrentSmoothCoordinate ? currentSmoothCoordinate.getX() : currentCoordinate.getX()) + , Util.formatDouble2StringDotAuto(needCurrentSmoothCoordinate ? currentSmoothCoordinate.getY() : currentCoordinate.getY()) + , Util.formatDouble2StringDotAuto(needCurrentSmoothCoordinate ? currentSmoothCoordinate.getZ() : currentCoordinate.getZ()) + , Util.formatDouble2StringDotAuto(distance.getDouble()) + , moveDigFill != null ? moveDigFill.getString() : "" + , moveK != null && moveK.value != null ? moveK.value.getString() : "" + , moveD != null && moveD.value != null ? moveD.value.getString() : "" + , stationData.stationAngle, stationData.stationDistance + , recordRemarks + , new Date() + , deviceInfoData); + + PointStakeDb.getInstance().save(pointStakeRecord); + + runOnUiThread(() -> { + recordPointLine.getValues().add(new PointValue(pointStakeRecord.measuredY, pointStakeRecord.measuredX).setLabel("")); + stopSoundPool(); + recordRemarks = ""; + if (preferences.getBoolean("key_is_tts_open", true)) { + SoundPoolUtil.getInstance().singlePlayStopRecord(); + } + ((LineChartRenderer) binding.lineChartView.getChartRenderer()).calculateMaxViewport(1.5f); + binding.lineChartView.onChartDataChange(); + }); + }); + } + + /** + * 显示的移动方法赋值 + */ + private void showTopMoveMethod() { + binding.tvDistance.setText(getString(R.string.distance)); + binding.tvDigFill.setText(getString(R.string.dig_fill)); + if (Device.getInstance().deviceType == DeviceTypeEnum.DEVICE_TYPE_TS) { + switch (PreferencesUtil.getMoveMethodTypeTS()) { +// case 0: +// binding.tvTopThree.setText(getString(R.string.k)); +// binding.tvTopFour.setText(getString(R.string.d)); +// break; + case 0: + binding.tvTopThree.setText(getString(R.string.to_before)); + binding.tvTopFour.setText(getString(R.string.to_left)); + break; + case 1: + binding.tvTopThree.setText(getString(R.string.to_north)); + binding.tvTopFour.setText(getString(R.string.to_east)); + break; + } + binding.topFiveSixLayout.setVisibility(View.VISIBLE); + } else { +// switch (PreferencesUtil.getMoveMethodTypeRTK()) { +// case 0: +// binding.tvTopThree.setText(getString(R.string.k)); +// binding.tvTopFour.setText(getString(R.string.d)); +// break; +// case 1: + binding.tvTopThree.setText(getString(R.string.to_north)); + binding.tvTopFour.setText(getString(R.string.to_east)); +// break; +// } + binding.topFiveSixLayout.setVisibility(View.GONE); + } + binding.tvTopFive.setText(getString(R.string.station_angle)); + binding.tvTopSix.setText(getString(R.string.station_angle_diff)); + } + + @Override + protected void onHelpClicked() { + HelpWebActivity.navigation2KnownPointStakingHelp(this); + } + + @Override + public boolean isShowTopBarHrPoleLayout() { + return false; + } + + private String jobId() { + return IntentUtil.stringExtra(getIntent(), KEY_JOB_ID); + } + + private static final String KEY_POINT_LIST = "key_point_list"; + + + public static void start(Context context, List stakingPointList) { + Gson gson = new Gson(); + Intent intent = new Intent(context, PointStakingActivity1.class); + intent.putExtra(KEY_POINT_LIST, gson.toJson(stakingPointList)); + context.startActivity(intent); + } + + public static void start(Context context) { + ThreadPoolUtil.execute(() -> { + String projectId = CachedProject.currentProjectId(); + String roadId = CachedCurrentRoad.currentRoadId(projectId); + String jobId = CachedCurrentJob.currentJobId(projectId); + Intent intent = new Intent(context, PointStakingActivity1.class); + intent.putExtra(KEY_JOB_ID, jobId); + intent.putExtra(KEY_PROJECT_ID, projectId); + context.startActivity(intent); + }); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + stopSoundPool(); + } + + private void stopSoundPool() { + SoundPoolUtil.getInstance().stop(); + } + + @Override + public void onRtkTiltSwitched(boolean onOff) { + super.onRtkTiltSwitched(onOff); + if (onOff) { + binding.baseSurveyStakingSetting.ivTiltPrimAuto.setImageResource(R.drawable.icon_survey_tilt_black); + binding.baseSurveyStakingSetting.tvTiltPrimAuto.setTextColor(getColor(R.color.black)); + } else { + binding.baseSurveyStakingSetting.ivTiltPrimAuto.setImageResource(R.drawable.icon_survey_tilt_gray); + binding.baseSurveyStakingSetting.tvTiltPrimAuto.setTextColor(getColor(R.color.color_BCBCBC)); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/project/survey/ui/lofting/pointlofting/record/RecordsActivity.java b/app/src/main/java/com/project/survey/ui/lofting/pointlofting/record/RecordsActivity.java index a9ec10b..1df4316 100644 --- a/app/src/main/java/com/project/survey/ui/lofting/pointlofting/record/RecordsActivity.java +++ b/app/src/main/java/com/project/survey/ui/lofting/pointlofting/record/RecordsActivity.java @@ -34,7 +34,9 @@ import com.hjq.permissions.XXPermissions; import com.hjq.shape.view.ShapeTextView; import com.project.survey.App; import com.project.survey.R; +import com.project.survey.constants.SPConstants; import com.project.survey.databinding.ActivityRecordsBinding; +import com.project.survey.model.ProjectBean; import com.project.survey.ui.lofting.pointlofting.record.util.IRecordsUtils; import com.project.survey.ui.lofting.pointlofting.record.util.RecordTypeConstants; import com.project.survey.ui.lofting.pointlofting.record.util.RecordsActivityClearUtils; @@ -43,6 +45,7 @@ import com.project.survey.ui.lofting.pointlofting.record.util.RecordsActivityFil import com.project.survey.ui.lofting.pointlofting.record.util.RecordsActivityHeaders; import com.project.survey.ui.lofting.pointlofting.record.util.RecordsUtilsFactory; import com.project.survey.ui.lofting.pointlofting.record.util.RecordsViewModelKt; +import com.project.survey.util.SPUtils; import org.polaric.colorful.ColorfulActivity; @@ -296,50 +299,50 @@ public class RecordsActivity extends ColorfulActivity { private void updateRecyclerView() { ThreadPoolUtil.execute(() -> { - UserConfig userConfig = LoadUserConfigKt.loadUserConfig(); - String projectId = LoadCurrentProjectIdKt.loadCurrentProjectId(true, userConfig); - if (StringUtil.isEmpty(projectId)) { - return; - } - String jobId = LoadCurrentJobIdKt.loadCurrentJobId(projectId, true, userConfig); - if (StringUtil.isEmpty(jobId)) { - return; - } - if (currentTypeFromSpinner == RecordTypeConstants.TYPE_WATER_PIPE_BACK_BREAK){ - String waterPipeId = LoadCurrentWaterPipeIdKt.loadCurrentWaterPipeId(projectId, true, userConfig); - if (StringUtil.isEmpty(waterPipeId)){ - return; - } - runOnUiThread(() -> { - IRecordsUtils recordsUtils = recordsUtilsMap.get(currentTypeFromSpinner); - if (recordsUtils != null) { - recordsUtils.update(binding.recyclerviewRecords, isSortByTimeAcs, - userConfig, - projectId, jobId, waterPipeId, - filterUtils.filterParameter()); - - } - }); - }else { - String roadId = LoadCurrentRoadIdKt.loadCurrentRoadId(projectId, true, userConfig); - if (StringUtil.isEmpty(roadId)) { - return; - } +// UserConfig userConfig = LoadUserConfigKt.loadUserConfig(); +// String projectId = LoadCurrentProjectIdKt.loadCurrentProjectId(true, userConfig); +// if (StringUtil.isEmpty(projectId)) { +// return; +// } +// String jobId = LoadCurrentJobIdKt.loadCurrentJobId(projectId, true, userConfig); +// if (StringUtil.isEmpty(jobId)) { +// return; +// } +// if (currentTypeFromSpinner == RecordTypeConstants.TYPE_WATER_PIPE_BACK_BREAK){ +// String waterPipeId = LoadCurrentWaterPipeIdKt.loadCurrentWaterPipeId(projectId, true, userConfig); +// if (StringUtil.isEmpty(waterPipeId)){ +// return; +// } +// runOnUiThread(() -> { +// IRecordsUtils recordsUtils = recordsUtilsMap.get(currentTypeFromSpinner); +// if (recordsUtils != null) { +// recordsUtils.update(binding.recyclerviewRecords, isSortByTimeAcs, +// userConfig, +// projectId, jobId, waterPipeId, +// filterUtils.filterParameter()); +// +// } +// }); +// }else { +// String roadId = LoadCurrentRoadIdKt.loadCurrentRoadId(projectId, true, userConfig); +// if (StringUtil.isEmpty(roadId)) { +// return; +// } runOnUiThread(() -> { IRecordsUtils recordsUtils = recordsUtilsMap.get(currentTypeFromSpinner); if (recordsUtils != null) { recordsUtils.update(binding.recyclerviewRecords, isSortByTimeAcs, - userConfig, - projectId, jobId, roadId, + null, + SPUtils.INSTANCE.getString(SPConstants.PROJECT_ID), "", "", filterUtils.filterParameter()); - if (RecordTypeConstants.TYPE_MEASURING_TAPE == currentTypeFromSpinner) { - //如果选中的是进尺,尝试加载数据 - holderInActivity.getViewModel().loadMeasuringTapeRecord(userConfig, roadId); - } +// if (RecordTypeConstants.TYPE_MEASURING_TAPE == currentTypeFromSpinner) { +// //如果选中的是进尺,尝试加载数据 +// holderInActivity.getViewModel().loadMeasuringTapeRecord(userConfig, roadId); +// } } }); - } +// } }); diff --git a/app/src/main/java/com/project/survey/ui/login/LoginInputCodeActivity.kt b/app/src/main/java/com/project/survey/ui/login/LoginInputCodeActivity.kt index f31eed9..58b2a3a 100644 --- a/app/src/main/java/com/project/survey/ui/login/LoginInputCodeActivity.kt +++ b/app/src/main/java/com/project/survey/ui/login/LoginInputCodeActivity.kt @@ -4,6 +4,7 @@ import androidx.activity.viewModels import androidx.lifecycle.lifecycleScope import com.project.survey.databinding.ActivityLoginInputCodeBinding import com.project.survey.extend.showSoftInput +import com.project.survey.extend.toast import com.project.survey.logic.viewmodel.LoginViewModel import com.project.survey.ui.base.BaseBindingActivity import com.project.survey.util.ActivityNavUtil @@ -61,7 +62,9 @@ class LoginInputCodeActivity : BaseBindingActivity(), O adapter.getItem(position)?.let { bean -> // 进入项目,设置当前项目 SPUtils.put(SPConstants.CURRENT_PROJECT, bean) + SPUtils.put(SPConstants.PROJECT_ID, bean.XMXX_CODE) // 存储配置--当前项目 ThreadPoolUtil.execute { //存储新的项目 ProjectDb.getInstance().save( - ProjectRecord(bean.BD_XMXX_ID, bean.XMXX_NAME, null, Date().time).apply { + ProjectRecord(bean.BD_XMXX_ID, bean.XMXX_NAME, CoordinateSystem.newCoordinateSystem(this), Date().time).apply { author = bean.XMXX_CONTACTNAME } ) diff --git a/app/src/main/java/com/project/survey/util/MockUtil.kt b/app/src/main/java/com/project/survey/util/MockUtil.kt new file mode 100644 index 0000000..fbb3e6c --- /dev/null +++ b/app/src/main/java/com/project/survey/util/MockUtil.kt @@ -0,0 +1,65 @@ +package com.project.survey.util + +import com.bingce.coordlib.model.CoordinateSystem +import com.bingce.data.base.user.UserConfig +import com.bingce.data.base.user.UserConfigConstants +import com.bingce.data.database.AppDataBase +import com.bingce.data.database.KeyValueDb +import com.bingce.data.database.ProjectDb +import com.bingce.data.surveyor.designdata.kv.KeyValueConstants +import com.bingce.data.surveyor.designdata.kv.KeyValueRecord +import com.bingce.data.surveyor.designdata.project.ProjectRecord +import com.bingce.utils.ThreadPoolUtil +import com.project.survey.App +import com.project.survey.constants.SPConstants +import java.util.Date + +object MockUtil { + + val isTest = false + + fun login(){ + SPUtils.put(SPConstants.ACCOUNT, "zhangsan") + SPUtils.put(SPConstants.TOKEN, "1234567890") + val personId = "123456" + SPUtils.put(SPConstants.PERSON_ID, personId) + SPUtils.put(SPConstants.MOBILE_PHONE, "15911112222") + + // 进入项目,设置当前项目 + val projectId = "111111" + SPUtils.put(SPConstants.PROJECT_ID, projectId) + + // 存储配置--当前项目 + ThreadPoolUtil.execute { + var userConfig = AppDataBase.getInstance().userConfigDao().findByLeanCloudUserId(personId) + if (userConfig == null) { //创建第一个用户配置--使用默认数据目录 + userConfig = UserConfig.newItem( + personId, + UserConfigConstants.VALUE_DEFAULT_DB_FOLDER + ) + AppDataBase.getInstance().userConfigDao().save(userConfig) + } + + //存储新的项目 + ProjectDb.getInstance().save( + ProjectRecord(projectId, "哈哈工程", + CoordinateSystem.newCoordinateSystem(App.instance.applicationContext), Date().time).apply { + author = "张哈哈" + } + ) + var currentProjectConfig = + KeyValueDb.getInstance().findData(KeyValueConstants.KEY_CURRENT_PROJECT_ID) + if (currentProjectConfig != null) { + currentProjectConfig.value = projectId + } else { + currentProjectConfig = KeyValueRecord(KeyValueConstants.KEY_CURRENT_PROJECT_ID, projectId) + } + KeyValueDb.getInstance().save(currentProjectConfig) + } + + } + + fun logout(){ + + } +} \ No newline at end of file