You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
765 lines
42 KiB
765 lines
42 KiB
7 months ago
|
package com.project.survey.ui;
|
||
|
|
||
|
import android.Manifest;
|
||
|
import android.content.ComponentName;
|
||
|
import android.content.Context;
|
||
|
import android.content.DialogInterface;
|
||
|
import android.content.Intent;
|
||
|
import android.content.pm.PackageManager;
|
||
|
import android.location.Location;
|
||
|
import android.location.LocationManager;
|
||
|
import android.os.Build;
|
||
|
import android.provider.Settings;
|
||
|
import android.view.View;
|
||
|
|
||
|
import androidx.annotation.NonNull;
|
||
|
import androidx.appcompat.app.AppCompatActivity;
|
||
|
import androidx.core.app.ActivityCompat;
|
||
|
import androidx.fragment.app.Fragment;
|
||
|
import androidx.lifecycle.Lifecycle;
|
||
|
import androidx.lifecycle.LifecycleEventObserver;
|
||
|
import androidx.lifecycle.LifecycleOwner;
|
||
|
|
||
|
import com.afollestad.materialdialogs.DialogAction;
|
||
|
import com.afollestad.materialdialogs.MaterialDialog;
|
||
|
import com.bingce.AppChannel;
|
||
|
import com.bingce.BaseApp;
|
||
|
import com.bingce.coordlib.model.Blh;
|
||
|
import com.bingce.coordlib.util.CoordUtil;
|
||
|
import com.bingce.data.cache.CachedCurrentCoordinateSystemKt;
|
||
|
import com.bingce.data.sync.GlobalFlowCenter;
|
||
|
import com.bingce.data.sync.utils.LeanCloudUserLoginStateUtils;
|
||
|
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.otg.OTGCommService;
|
||
|
import com.bingce.device.service.comm.socket.TsSocketService;
|
||
|
import com.bingce.device.service.comm.spp.BTService;
|
||
|
import com.bingce.device.service.ntrip_sdk.CmccSdkService;
|
||
|
import com.bingce.device.service.ntrip_sdk.LuoWangSdkService;
|
||
|
import com.bingce.device.service.ntrip_sdk.NtripService;
|
||
|
import com.bingce.device.service.ntrip_sdk.QxwzSdkService;
|
||
|
import com.bingce.device.service.ntrip_sdk.SixentsSdkService;
|
||
|
import com.bingce.device.ui.ConnectRtkActivity;
|
||
|
import com.bingce.device.ui.ConnectTSActivity;
|
||
|
import com.bingce.device.ui.dialog.DialogUtil;
|
||
|
import com.bingce.device.ui.utils.DeviceUtil;
|
||
|
import com.bingce.device.ui.widget.BCProgressDialog;
|
||
|
import com.bingce.rtk.command.RTK;
|
||
|
import com.bingce.rtk.command.qxwz.QxwzRTK;
|
||
|
import com.bingce.rtk.enums.DataLinkModeEnum;
|
||
|
import com.bingce.rtk.enums.NetworkModeEnum;
|
||
|
import com.bingce.rtk.enums.NtripCorsProviderEnum;
|
||
|
import com.bingce.rtk.event.RtkCheckBaseMoveEvent;
|
||
|
import com.bingce.rtk.event.RtkCmdAnswerEvent;
|
||
|
import com.bingce.rtk.event.RtkCmdQueueSendEvent;
|
||
|
import com.bingce.rtk.event.RtkCmdUiEvent;
|
||
|
import com.bingce.rtk.event.RtkReceivedSerialNumberEvent;
|
||
|
import com.bingce.rtk.event.RtkSpeechEvent;
|
||
|
import com.bingce.rtk.event.RtkStartCmccServiceEvent;
|
||
|
import com.bingce.rtk.event.RtkStartLuoWangServiceEvent;
|
||
|
import com.bingce.rtk.event.RtkStartNtripServiceEvent;
|
||
|
import com.bingce.rtk.event.RtkStartQxwzSdkServiceEvent;
|
||
|
import com.bingce.rtk.event.RtkStartSixentsServiceEvent;
|
||
|
import com.bingce.rtk.event.RtkStopNtripSDKEvent;
|
||
|
import com.bingce.rtk.gnss.Gnss;
|
||
|
import com.bingce.rtk.model.GnssPosition;
|
||
|
import com.bingce.rtk.util.GnssUtil;
|
||
|
import com.bingce.totalstation.TotalStation;
|
||
|
import com.bingce.totalstation.TsConfig;
|
||
|
import com.bingce.totalstation.enums.SetupStationMethodEnum;
|
||
|
import com.bingce.totalstation.event.TsUpdateStatusEvent;
|
||
|
import com.bingce.utils.AppCompatActivityProviderUtils;
|
||
|
import com.bingce.utils.AppUtil;
|
||
|
import com.bingce.utils.IProvider;
|
||
|
import com.bingce.utils.LCDeviceUtil;
|
||
|
import com.bingce.utils.RomUtil;
|
||
|
import com.bingce.utils.SdkUtils;
|
||
|
import com.bingce.utils.SoundPoolUtil;
|
||
|
import com.bingce.utils.ThreadPoolUtil;
|
||
|
import com.bingce.utils.Util;
|
||
|
import com.bingce.utils.ValidateUtil;
|
||
|
import com.bingce.utils.VipManager;
|
||
|
import com.hjq.permissions.OnPermissionCallback;
|
||
|
import com.hjq.permissions.OnPermissionPageCallback;
|
||
|
import com.hjq.permissions.Permission;
|
||
|
import com.hjq.permissions.XXPermissions;
|
||
|
import com.project.survey.App;
|
||
|
import com.project.survey.R;
|
||
|
import com.project.survey.ui.instrument.basestationtranslation.RtkBaseCorrectActivity;
|
||
|
|
||
|
import net.tatans.tensorflowtts.tts.TtsManager;
|
||
|
|
||
|
import org.greenrobot.eventbus.EventBus;
|
||
|
import org.greenrobot.eventbus.Subscribe;
|
||
|
import org.greenrobot.eventbus.ThreadMode;
|
||
|
|
||
|
import java.util.List;
|
||
|
|
||
|
import alibaba.fastjson.JSON;
|
||
|
import alibaba.fastjson.JSONObject;
|
||
|
import blankj.utilcode.util.ActivityUtils;
|
||
|
import blankj.utilcode.util.ServiceUtils;
|
||
|
import blankj.utilcode.util.StringUtils;
|
||
|
import blankj.utilcode.util.ToastUtils;
|
||
|
import blankj.utilcode.util.Utils;
|
||
|
import cn.leancloud.LCUser;
|
||
|
import cn.leancloud.types.LCGeoPoint;
|
||
|
import cn.liuyanbing.surveyor.model.util.CUtil;
|
||
|
|
||
|
public class MainActivityUtils extends AppCompatActivityProviderUtils {
|
||
|
private boolean gnssServerReady = false;
|
||
|
private MaterialDialog cenLngUnusualDialog;
|
||
|
private MaterialDialog langDialog, unbindDeviceDialog;
|
||
|
private BCProgressDialog deviceConnectingProgressDialog;
|
||
|
private final CachedCurrentCoordinateSystemKt cachedCoordinateSystemKt;
|
||
|
|
||
|
public MainActivityUtils(AppCompatActivity activity,
|
||
|
IProvider<AppCompatActivity> 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<String> 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<String> permissions, boolean all) {
|
||
|
checkConnectLast();
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onDenied(List<String> 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<String> permissions, boolean all) {
|
||
|
if (all) {
|
||
|
checkConnectLast();
|
||
|
} else {
|
||
|
requestBluetoothPermission();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onDenied(List<String> 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<String> permissions, boolean all) {
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onDenied(List<String> 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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|