main
parent
35d14a481c
commit
6fbbdb4342
5 changed files with 676 additions and 2 deletions
@ -0,0 +1,175 @@ |
||||
package com.project.survey.ui.instrument.coordinatesystem; |
||||
|
||||
import android.content.Context; |
||||
import android.content.Intent; |
||||
import android.os.Bundle; |
||||
import android.view.KeyEvent; |
||||
import android.view.Menu; |
||||
import android.view.MenuItem; |
||||
import android.view.View; |
||||
|
||||
import androidx.annotation.Nullable; |
||||
import androidx.appcompat.widget.Toolbar; |
||||
import androidx.fragment.app.Fragment; |
||||
import androidx.fragment.app.FragmentActivity; |
||||
|
||||
import com.bingce.activity.AutoLandscapeBingCeActivity; |
||||
import com.bingce.device.ui.coordinatesystem.fragment.AbstractCoordinateSystemContainerFragment; |
||||
import com.bingce.device.ui.databinding.ActivityCoordinateSystemBinding; |
||||
import com.bingce.utils.ActivityUtils; |
||||
import com.bingce.utils.IntentUtil; |
||||
import com.bingce.utils.StringUtil; |
||||
import com.project.survey.R; |
||||
import com.project.survey.ui.instrument.coordinatesystem.fragment.CoordinateSystemContainerFragment; |
||||
|
||||
import blankj.utilcode.util.Utils; |
||||
|
||||
|
||||
public class BingCeCoordinateSystemActivity extends AutoLandscapeBingCeActivity { |
||||
@Override |
||||
protected void onBingCeCreate(@Nullable Bundle savedInstanceState) { |
||||
ActivityCoordinateSystemBinding binding = ActivityCoordinateSystemBinding.inflate(getLayoutInflater()); |
||||
setContentView(binding.getRoot()); |
||||
Toolbar mToolbar = findViewById(R.id.toolbar); |
||||
setSupportActionBar(mToolbar); |
||||
if (getSupportActionBar() != null) |
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
||||
|
||||
boolean isReturnSys = getIntent().getBooleanExtra(CoordinateSystemContainerFragment.KEY_RETURN_SYS, false); |
||||
if (isReturnSys) { |
||||
binding.activityCoordinateSystemBtnCalc.setVisibility(View.GONE); |
||||
} |
||||
|
||||
Fragment coordinatorFragment = null; |
||||
if (getIntent() != null && getIntent().getExtras() != null) { |
||||
coordinatorFragment = CoordinateSystemContainerFragment.newInstance(getIntent().getExtras()); |
||||
String title = getIntent().getStringExtra(CoordinateSystemContainerFragment.KEY_TITLE); |
||||
if (title != null && !title.isEmpty()) { |
||||
setTitle(title); |
||||
} |
||||
} |
||||
|
||||
if (coordinatorFragment == null) { |
||||
coordinatorFragment = new CoordinateSystemContainerFragment(); |
||||
} |
||||
|
||||
getSupportFragmentManager() |
||||
.beginTransaction() |
||||
.add(R.id.activity_coordinate_system_fragment, coordinatorFragment) |
||||
.commit(); |
||||
|
||||
Fragment finalCoordinatorFragment = coordinatorFragment; |
||||
binding.activityCoordinateSystemBtnQuit.setOnClickListener(v -> { |
||||
if (finalCoordinatorFragment instanceof CoordinateSystemContainerFragment) { |
||||
((CoordinateSystemContainerFragment) finalCoordinatorFragment).onQuitClicked(); |
||||
} |
||||
}); |
||||
|
||||
binding.activityCoordinateSystemBtnAccept.setOnClickListener(v -> { |
||||
if (finalCoordinatorFragment instanceof CoordinateSystemContainerFragment) { |
||||
((CoordinateSystemContainerFragment) finalCoordinatorFragment).onAcceptClicked(); |
||||
} |
||||
}); |
||||
|
||||
binding.activityCoordinateSystemBtnCalc.setOnClickListener(v -> { |
||||
if (finalCoordinatorFragment instanceof CoordinateSystemContainerFragment) { |
||||
((CoordinateSystemContainerFragment) finalCoordinatorFragment).onCalcClicked(); |
||||
} |
||||
}); |
||||
|
||||
boolean isReadOnly = IntentUtil.boolExtra(getIntent(), CoordinateSystemContainerFragment.KEY_READ_ONLY); |
||||
binding.bottomLayout.setVisibility(isReadOnly ? View.GONE : View.VISIBLE); |
||||
} |
||||
|
||||
@Override |
||||
public boolean onCreateOptionsMenu(Menu menu) { |
||||
getMenuInflater().inflate(R.menu.menu_activity_rtk_coordinate_system, menu); |
||||
return super.onCreateOptionsMenu(menu); |
||||
} |
||||
|
||||
@Override |
||||
public boolean onOptionsItemSelected(MenuItem item) { |
||||
int itemId = item.getItemId(); |
||||
if (itemId == android.R.id.home) { |
||||
finish(); |
||||
} else if (itemId == R.id.menu_help) { |
||||
if (Utils.getApp() instanceof IHelper) { |
||||
((IHelper) Utils.getApp()).onNavigation2CoordinateSystemHelp(); |
||||
} |
||||
} |
||||
return super.onOptionsItemSelected(item); |
||||
} |
||||
|
||||
@Override |
||||
public boolean onKeyDown(int keyCode, KeyEvent event) { |
||||
switch (keyCode) { |
||||
case KeyEvent.KEYCODE_BACK: |
||||
finish(); |
||||
break; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* 查看并修改当前坐标系,并且直接跳转到椭球参数页面 |
||||
*/ |
||||
public static void skip2ProjViewAndModifyCurrentCoordinateSystem(Context context) { |
||||
Intent intent = IntentUtil.forceStaticMethodIntent(context, BingCeCoordinateSystemActivity.class); |
||||
intent.putExtra(CoordinateSystemContainerFragment.KEY_READ_ONLY, false); |
||||
intent.putExtra(CoordinateSystemContainerFragment.KEY_RETURN_SYS, false); |
||||
intent.putExtra(CoordinateSystemContainerFragment.KEY_SKIP2PROJ, true); |
||||
context.startActivity(intent); |
||||
} |
||||
|
||||
/** |
||||
* 查看坐标系,不能修改 |
||||
*/ |
||||
public static void view(Context context, String title, String jsonString) { |
||||
Intent intent = IntentUtil.forceStaticMethodIntent(context, BingCeCoordinateSystemActivity.class); |
||||
intent.putExtra(CoordinateSystemContainerFragment.KEY_TITLE, title); |
||||
intent.putExtra(CoordinateSystemContainerFragment.KEY_TXT, jsonString); |
||||
intent.putExtra(CoordinateSystemContainerFragment.KEY_READ_ONLY, true); |
||||
intent.putExtra(CoordinateSystemContainerFragment.KEY_RETURN_SYS, false); |
||||
intent.putExtra(CoordinateSystemContainerFragment.KEY_SKIP2PROJ, false); |
||||
context.startActivity(intent); |
||||
} |
||||
|
||||
/** |
||||
* 查看并修改当前坐标系 |
||||
*/ |
||||
public static void viewAndModifyCurrentCoordinateSystem(Context context) { |
||||
Intent intent = IntentUtil.forceStaticMethodIntent(context, BingCeCoordinateSystemActivity.class); |
||||
context.startActivity(intent); |
||||
} |
||||
|
||||
/** |
||||
* 选择「预设」的坐标系后,进入其详情界面尝试修改,然后返回修改后的json值 |
||||
*/ |
||||
public static void modifyPresetCoordinateSystemBeforeReturn( |
||||
FragmentActivity context, String jsonString, String coordinateSystemName, |
||||
boolean readonly, boolean returnSys, ICoordinateSystem coordinateSystem) { |
||||
Intent intent = IntentUtil.forceStaticMethodIntent(context, BingCeCoordinateSystemActivity.class); |
||||
intent.putExtra(CoordinateSystemContainerFragment.KEY_TITLE, coordinateSystemName); |
||||
intent.putExtra(CoordinateSystemContainerFragment.KEY_TXT, jsonString); |
||||
intent.putExtra(CoordinateSystemContainerFragment.KEY_READ_ONLY, readonly); |
||||
intent.putExtra(CoordinateSystemContainerFragment.KEY_RETURN_SYS, returnSys); |
||||
|
||||
ActivityUtils.startActivityForResults(context, intent, result -> { |
||||
if (result != null && result.getResultCode() == RESULT_OK) { |
||||
Intent data = result.getData(); |
||||
String json = data == null ? null : data.getStringExtra(AbstractCoordinateSystemContainerFragment.KEY_TXT); |
||||
if (coordinateSystem != null && !StringUtil.isEmpty(json)) { |
||||
coordinateSystem.onGetCoordinateSystemJson(json); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
public interface ICoordinateSystem { |
||||
void onGetCoordinateSystemJson(String jsonString); |
||||
} |
||||
|
||||
public interface IHelper { |
||||
void onNavigation2CoordinateSystemHelp(); |
||||
} |
||||
} |
@ -0,0 +1,104 @@ |
||||
package com.project.survey.ui.instrument.coordinatesystem; |
||||
|
||||
import android.content.Context; |
||||
|
||||
import androidx.annotation.WorkerThread; |
||||
import androidx.appcompat.app.AppCompatActivity; |
||||
import androidx.fragment.app.Fragment; |
||||
import androidx.lifecycle.Lifecycle; |
||||
import androidx.lifecycle.LiveData; |
||||
import androidx.lifecycle.MutableLiveData; |
||||
|
||||
import com.bingce.coordlib.model.CoordinateSystem; |
||||
import com.bingce.data.cache.CacheHelper; |
||||
import com.bingce.data.cache.CachedObserver; |
||||
import com.bingce.data.database.DBQueryConstant; |
||||
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.project.ProjectConstants; |
||||
import com.bingce.data.surveyor.designdata.project.ProjectRecord; |
||||
import com.bingce.utils.IProvider; |
||||
import com.bingce.utils.KVLiveDataIgnoreUserSwitch; |
||||
|
||||
import blankj.utilcode.util.Utils; |
||||
|
||||
public class CachedCurrentCoordinateSystem extends CacheHelper { |
||||
private final KVLiveDataIgnoreUserSwitch currentProjectKV = new KVLiveDataIgnoreUserSwitch(KeyValueConstants.KEY_CURRENT_PROJECT_ID); |
||||
private final IProvider<Context> context; |
||||
//当前项目实例
|
||||
private LiveData<ProjectRecord> projectRecordLiveData = null; |
||||
//当前坐标系实例
|
||||
private final MutableLiveData<CoordinateSystem> currentCoordinateSystemMutableLiveData = new MutableLiveData<>(); |
||||
|
||||
public CachedCurrentCoordinateSystem(AppCompatActivity activity) { |
||||
super(activity.getLifecycle()); |
||||
context = () -> activity; |
||||
addLifeCycle(getLifecycle()); |
||||
} |
||||
|
||||
public CachedCurrentCoordinateSystem(Fragment fragment) { |
||||
super(fragment.getLifecycle()); |
||||
context = fragment::getContext; |
||||
addLifeCycle(getLifecycle()); |
||||
} |
||||
|
||||
protected void addLifeCycle(Lifecycle lifecycle) { |
||||
//1.监听当前坐标系id
|
||||
currentProjectKV |
||||
.observe(this, configRecord -> { |
||||
// if (configRecord == null) {
|
||||
// return;
|
||||
// }
|
||||
// if (projectRecordLiveData != null) {
|
||||
// projectRecordLiveData.removeObservers(this);
|
||||
// }
|
||||
// projectRecordLiveData = ProjectDb.getInstance()
|
||||
// .rawQueryLiveData(DBQueryConstant.findById(ProjectConstants.DB_NAME, configRecord.value));
|
||||
//
|
||||
// projectRecordLiveData.observe(this, projectRecord -> {
|
||||
// CoordinateSystem coordinateSystem = projectRecord == null ? null : projectRecord.coordinateSystem;
|
||||
// currentCoordinateSystemMutableLiveData.setValue(coordinateSystem == null ? CoordinateSystem.newCoordinateSystem(context.value()) : coordinateSystem);
|
||||
// });
|
||||
currentCoordinateSystemMutableLiveData.setValue(CoordinateSystem.newCoordinateSystem(context.value())); |
||||
|
||||
}); |
||||
} |
||||
|
||||
public CoordinateSystem coordinateSystem() { |
||||
CoordinateSystem coordinateRecord = currentCoordinateSystemMutableLiveData.getValue(); |
||||
if (coordinateRecord == null) { |
||||
throw new RuntimeException("coordinate system not ready"); |
||||
} |
||||
return coordinateRecord; |
||||
} |
||||
|
||||
public boolean isDataReady() { |
||||
return currentCoordinateSystemMutableLiveData.getValue() != null; |
||||
} |
||||
|
||||
public void observe(CachedObserver<CoordinateSystem> observer) { |
||||
currentCoordinateSystemMutableLiveData.observe(this, observer); |
||||
} |
||||
|
||||
|
||||
@WorkerThread |
||||
public static CoordinateSystem currentCoordinateSystem() { |
||||
String projectId = KeyValueDb.currentProjectId(); |
||||
ProjectRecord projectRecord = ProjectDb.getInstance() |
||||
.rawQueryData(DBQueryConstant.findById(ProjectConstants.DB_NAME, projectId)); |
||||
return projectRecord == null ? CoordinateSystem.newCoordinateSystem(Utils.getApp()) : projectRecord.coordinateSystem; |
||||
} |
||||
|
||||
@WorkerThread |
||||
public static void saveCurrentCoordinateSystem(CoordinateSystem system) { |
||||
String projectId = KeyValueDb.currentProjectId(); |
||||
ProjectRecord projectRecord = ProjectDb.getInstance() |
||||
.rawQueryData(DBQueryConstant.findById(ProjectConstants.DB_NAME, projectId)); |
||||
if (projectRecord == null) { |
||||
return; |
||||
} |
||||
projectRecord.coordinateSystem = system; |
||||
ProjectDb.getInstance().save(projectRecord); |
||||
} |
||||
} |
@ -0,0 +1,392 @@ |
||||
package com.project.survey.ui.instrument.coordinatesystem.fragment; |
||||
|
||||
import android.app.Activity; |
||||
import android.content.Intent; |
||||
import android.graphics.Color; |
||||
import android.os.Bundle; |
||||
import android.view.LayoutInflater; |
||||
import android.view.Menu; |
||||
import android.view.MenuInflater; |
||||
import android.view.MenuItem; |
||||
import android.view.View; |
||||
import android.view.ViewGroup; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.annotation.Nullable; |
||||
import androidx.fragment.app.Fragment; |
||||
import androidx.fragment.app.FragmentActivity; |
||||
import androidx.fragment.app.FragmentManager; |
||||
import androidx.fragment.app.FragmentPagerAdapter; |
||||
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.cache.AbstractCachedObserver; |
||||
import com.bingce.data.database.CoordinateSystemDb; |
||||
import com.bingce.data.database.DBQueryConstant; |
||||
import com.bingce.data.database.KeyValueDb; |
||||
import com.bingce.data.database.ProjectDb; |
||||
import com.bingce.data.surveyor.designdata.coordinate.CoordinateSystemConstants; |
||||
import com.bingce.data.surveyor.designdata.coordinate.CoordinateSystemRecord; |
||||
import com.bingce.data.surveyor.designdata.kv.KeyValueConstants; |
||||
import com.bingce.data.surveyor.designdata.kv.KeyValueRecord; |
||||
import com.bingce.data.surveyor.designdata.project.ProjectConstants; |
||||
import com.bingce.data.surveyor.designdata.project.ProjectRecord; |
||||
import com.bingce.device.Device; |
||||
import com.bingce.device.ui.coordinatesystem.event.UpdateCoordinateSystemEvent; |
||||
import com.bingce.device.ui.coordinatesystem.fragment.AbstractCoordinateSystemContainerFragment; |
||||
import com.bingce.device.ui.coordinatesystem.fragment.BaseCorrectionFragment; |
||||
import com.bingce.device.ui.coordinatesystem.fragment.CoordinatorFragmentInterface; |
||||
import com.bingce.device.ui.coordinatesystem.fragment.DatumTransformFragment; |
||||
import com.bingce.device.ui.coordinatesystem.fragment.ElevationFittingFragment; |
||||
import com.bingce.device.ui.coordinatesystem.fragment.EllipsoidFragment; |
||||
import com.bingce.device.ui.coordinatesystem.fragment.GridTransformFragment; |
||||
import com.bingce.device.ui.coordinatesystem.fragment.ProjectionFragment; |
||||
import com.bingce.device.ui.utils.CoordSysShareUtil; |
||||
import com.bingce.dialog.DialogUtils; |
||||
import com.bingce.error.BingCeErrorCode; |
||||
import com.bingce.event.SingleMessageEvent; |
||||
import com.bingce.surveyorBase.R; |
||||
import com.bingce.ui.coordinatesystem.PresetCoordinateSystemV2Activity; |
||||
import com.bingce.utils.SoftKeyUtils; |
||||
import com.bingce.utils.ThreadPoolUtil; |
||||
import com.bingce.utils.ValidateUtil; |
||||
import com.flyco.tablayout.SlidingTabLayout; |
||||
import com.project.survey.ui.instrument.coordinatesystem.CachedCurrentCoordinateSystem; |
||||
import com.rengwuxian.materialedittext.MaterialEditText; |
||||
|
||||
import org.greenrobot.eventbus.EventBus; |
||||
import org.greenrobot.eventbus.Subscribe; |
||||
import org.greenrobot.eventbus.ThreadMode; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
import blankj.utilcode.util.StringUtils; |
||||
import blankj.utilcode.util.ToastUtils; |
||||
|
||||
public class CoordinateSystemContainerFragment extends AbstractCoordinateSystemContainerFragment { |
||||
protected final CachedCurrentCoordinateSystem cachedCoordinateSystem = new CachedCurrentCoordinateSystem(this); |
||||
private MaterialEditText met_name; |
||||
private ViewPager mViewPager; |
||||
private SlidingTabLayout mSlidingTabLayout; |
||||
private boolean isReturnSys = false; |
||||
private boolean isReadOnly = false; |
||||
private boolean skip2Proj = false; |
||||
private final CoordSysShareUtil.Export export = new CoordSysShareUtil.Export(); |
||||
private final CoordSysShareUtil.Import anImport = new CoordSysShareUtil.Import(); |
||||
|
||||
@Override |
||||
public void onCreate(@Nullable Bundle savedInstanceState) { |
||||
super.onCreate(savedInstanceState); |
||||
EventBus.getDefault().register(this); |
||||
} |
||||
|
||||
protected View contentView(LayoutInflater inflater, @Nullable ViewGroup container) { |
||||
return inflater.inflate(R.layout.fragment_coordinate_system, container, false); |
||||
} |
||||
|
||||
@Override |
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
||||
View view = contentView(inflater, container); |
||||
met_name = view.findViewById(R.id.fragment_coordinate_system_name); |
||||
mViewPager = view.findViewById(R.id.fragment_coordinate_system_viewpager); |
||||
mSlidingTabLayout = view.findViewById(R.id.fragment_coordinate_system_viewpager_tab); |
||||
return view; |
||||
} |
||||
|
||||
@Override |
||||
protected void onViewReady(CoordinatorFragmentInterface.ICoordinatorContainerFragment container, CoordinateSystem coordinateSystem) { |
||||
setHasOptionsMenu(true); |
||||
initMaterialEditTextColor(); |
||||
met_name.setText(coordinateSystem.getName()); |
||||
|
||||
String[] mTitles = new String[]{getString(R.string.ellipsoid), getString(R.string.projection) |
||||
, getString(R.string.datum_transform), getString(R.string.plane_transform) |
||||
, getString(R.string.elevation_fitting), getString(R.string.base_correction_parameters)}; |
||||
|
||||
if (getArguments() != null) { |
||||
isReadOnly = getArguments().getBoolean(KEY_READ_ONLY, false); |
||||
//如果是只读,需要隐藏底部button,将name设置为只读
|
||||
if (isReadOnly && getView() != null) { |
||||
View bottomLayout = getView().findViewById(R.id.bottom_layout); |
||||
if (bottomLayout != null) { |
||||
bottomLayout.setVisibility(View.INVISIBLE); |
||||
} |
||||
met_name.setEnabled(false); |
||||
} |
||||
} |
||||
ArrayList<Fragment> mFragments = new ArrayList<>(); |
||||
mFragments.add(EllipsoidFragment.newInstance(getArguments())); |
||||
mFragments.add(ProjectionFragment.newInstance(getArguments())); |
||||
mFragments.add(DatumTransformFragment.newInstance(getArguments())); |
||||
mFragments.add(GridTransformFragment.newInstance(getArguments())); |
||||
mFragments.add(ElevationFittingFragment.newInstance(getArguments())); |
||||
mFragments.add(BaseCorrectionFragment.newInstance(getArguments())); |
||||
|
||||
for (Fragment fragment : mFragments) { |
||||
if (fragment instanceof CoordinatorFragmentInterface.ICoordinatorAttributeFragment) { |
||||
container.register((CoordinatorFragmentInterface.ICoordinatorAttributeFragment) fragment); |
||||
} |
||||
} |
||||
|
||||
mViewPager.setAdapter(new MyPagerAdapter(getChildFragmentManager(), mTitles, mFragments)); |
||||
mViewPager.setOffscreenPageLimit(10); |
||||
|
||||
mSlidingTabLayout.setViewPager(mViewPager); |
||||
|
||||
mViewPager.setElevation(0); |
||||
mSlidingTabLayout.setElevation(10); |
||||
|
||||
if (getArguments() != null) { |
||||
if (getArguments().containsKey("tabColor") && mSlidingTabLayout != null) |
||||
mSlidingTabLayout.setBackgroundColor(getArguments().getInt("tabColor")); |
||||
isReturnSys = getArguments().getBoolean(KEY_RETURN_SYS, false); |
||||
skip2Proj = getArguments().getBoolean(KEY_SKIP2PROJ, false); |
||||
if (skip2Proj) { |
||||
mSlidingTabLayout.setCurrentTab(1, true); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
protected void observeCurrentCoordinateSystem(AbstractCachedObserver<CoordinateSystem> observer) { |
||||
cachedCoordinateSystem.observe(observer); |
||||
} |
||||
|
||||
public void onQuitClicked() { |
||||
getActivity().finish(); |
||||
} |
||||
|
||||
public void onAcceptClicked() { |
||||
SoftKeyUtils.hideSoftKey(); |
||||
save(() -> { |
||||
ToastUtils.showShort(R.string.save_success); |
||||
getActivity().finish(); |
||||
}); |
||||
} |
||||
|
||||
public void onCalcClicked() { |
||||
mSlidingTabLayout.setCurrentTab(1, true); |
||||
new MaterialDialog.Builder(getActivity()) |
||||
.title(R.string.hint) |
||||
.content(R.string.seven_or_four_para_hint) |
||||
.positiveText(R.string.go_to_config) |
||||
.negativeText(R.string.configured) |
||||
.onNegative((dialog, which) -> { |
||||
save(() -> { |
||||
EventBus.getDefault().post(new SingleMessageEvent("coordinate_system_parameter_calc")); |
||||
}); |
||||
}) |
||||
.show(); |
||||
} |
||||
|
||||
private void save(Runnable success) { |
||||
String name = ValidateUtil.filterSpecialChar(met_name.getText().toString().trim()); |
||||
if (StringUtils.isEmpty(name)) { |
||||
return; |
||||
} |
||||
setCoordinateSystemName(name); |
||||
checkFragmentsAndSyncData2Object(new CoordinatorFragmentInterface.ISaveCallback() { |
||||
@Override |
||||
public void onSuccess(CoordinateSystem coordinateSystem) { |
||||
if (isReturnSys) { |
||||
Intent intent = new Intent(); |
||||
intent.putExtra(KEY_TXT, CoordinateSystemUtil.exportCoordSysString(coordinateSystem)); |
||||
getActivity().setResult(Activity.RESULT_OK, intent); |
||||
success.run(); |
||||
} else { |
||||
ThreadPoolUtil.execute(() -> { |
||||
//搜索当前坐标系
|
||||
KeyValueRecord currentProjectConfig = KeyValueDb.getInstance().findData(KeyValueConstants.KEY_CURRENT_PROJECT_ID); |
||||
if (currentProjectConfig == null) { |
||||
BingCeErrorCode.toast(BingCeErrorCode.NO_CURRENT_PROJECT); |
||||
return; |
||||
} |
||||
ProjectRecord currentProjectRecord = ProjectDb.getInstance() |
||||
.rawQueryData(DBQueryConstant.findById(ProjectConstants.DB_NAME, currentProjectConfig.value)); |
||||
if (currentProjectRecord == null) { |
||||
BingCeErrorCode.toast(BingCeErrorCode.NO_FOUND_PROJECT_BY_ID); |
||||
return; |
||||
} |
||||
currentProjectRecord.coordinateSystem = coordinateSystem; |
||||
ProjectDb.getInstance().save(currentProjectRecord); |
||||
|
||||
//切换线路
|
||||
ThreadPoolUtil.executeInMain(success); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onFailure(int index, CoordinatorFragmentInterface.ICoordinatorAttributeFragment listener) { |
||||
mSlidingTabLayout.setCurrentTab(index, true); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { |
||||
super.onCreateOptionsMenu(menu, inflater); |
||||
if (getArguments() != null) { |
||||
isReadOnly = getArguments().getBoolean(KEY_READ_ONLY, false); |
||||
} |
||||
if (!isReadOnly && !isReturnSys) {//如果只读,就不显示右上角菜单
|
||||
inflater.inflate(R.menu.menu_fragment_coordinate_system, menu); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public boolean onOptionsItemSelected(MenuItem item) { |
||||
int itemId = item.getItemId(); |
||||
if (itemId == R.id.menu_fragment_coordinate_system_library) { |
||||
FragmentActivity activity = getActivity(); |
||||
if (activity != null) { |
||||
PresetCoordinateSystemV2Activity.selectCoordinateSystem(activity, coordinateSystem -> { |
||||
if (coordinateSystem != null) { |
||||
met_name.setText(coordinateSystem.getName()); |
||||
onCoordinateSystemChanged(coordinateSystem); |
||||
} |
||||
}); |
||||
} |
||||
} else if (itemId == R.id.menu_fragment_coordinate_system_save) { |
||||
//先收集界面内数据
|
||||
String name = ValidateUtil.filterSpecialChar(met_name.getText().toString().trim()); |
||||
if (StringUtils.isEmpty(name)) { |
||||
ToastUtils.showShort(R.string.coordinate_system_name_cannot_be_empty); |
||||
return true; |
||||
} |
||||
setCoordinateSystemName(name); |
||||
checkFragmentsAndSyncData2Object(new CoordinatorFragmentInterface.ISaveCallback() { |
||||
@Override |
||||
public void onSuccess(CoordinateSystem coordinateSystem) { |
||||
ThreadPoolUtil.execute(() -> { |
||||
List<CoordinateSystemRecord> records = CoordinateSystemDb.getInstance() |
||||
.rawQueryListData(DBQueryConstant.findAll(CoordinateSystemConstants.DB_NAME)); |
||||
//检测是否有重名
|
||||
List<CoordinateSystemRecord> sameNameList = new ArrayList<>(); |
||||
if (records != null) { |
||||
for (CoordinateSystemRecord record : records) { |
||||
if (record == null) { |
||||
continue; |
||||
} |
||||
if (record.coordinateSystem.getName().equals(coordinateSystem.getName())) { |
||||
sameNameList.add(record); |
||||
} |
||||
} |
||||
} |
||||
if (sameNameList.isEmpty()) { |
||||
CoordinateSystemRecord record = new CoordinateSystemRecord(coordinateSystem, new Date()); |
||||
CoordinateSystemDb.getInstance().save(record); |
||||
ToastUtils.showShort(R.string.save_success); |
||||
} else { |
||||
ThreadPoolUtil.executeInMain(() -> { |
||||
DialogUtils.tips(getContext(), |
||||
getString(R.string.warning), |
||||
getString(R.string.already_has_same_name_coordinate_system_r_u_sure_overwrite), |
||||
() -> { |
||||
//覆盖存储
|
||||
ThreadPoolUtil.execute(() -> { |
||||
for (CoordinateSystemRecord record : sameNameList) { |
||||
record.coordinateSystem = coordinateSystem; |
||||
} |
||||
CoordinateSystemDb.getInstance().save(sameNameList); |
||||
ToastUtils.showShort(R.string.save_success); |
||||
}); |
||||
}, |
||||
null); |
||||
}); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public void onFailure(int index, CoordinatorFragmentInterface.ICoordinatorAttributeFragment listener) { |
||||
mSlidingTabLayout.setCurrentTab(index, true); |
||||
} |
||||
}); |
||||
} else if (itemId == R.id.menu_fragment_coordinate_system_share) { |
||||
showShareParametersDialog(); |
||||
} else if (itemId == R.id.menu_fragment_coordinate_system_import) { |
||||
showImportParametersDialog(); |
||||
} |
||||
return super.onOptionsItemSelected(item); |
||||
} |
||||
|
||||
private void showShareParametersDialog() { |
||||
export.showSharedDialog(getContext(), currentCoordinateSystem()); |
||||
} |
||||
|
||||
private void showImportParametersDialog() { |
||||
anImport.showImportDialog(getContext(), system -> { |
||||
met_name.setText(system.getName()); |
||||
onCoordinateSystemChanged(system); |
||||
}); |
||||
} |
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN) |
||||
public void onMessageEvent(UpdateCoordinateSystemEvent event) { |
||||
onCoordinateSystemChanged(null); |
||||
} |
||||
|
||||
@Override |
||||
public void onDestroy() { |
||||
super.onDestroy(); |
||||
EventBus.getDefault().unregister(this); |
||||
} |
||||
|
||||
private void initMaterialEditTextColor() { |
||||
if (Device.getInstance().isThemeDark) { |
||||
met_name.setMetTextColor(Color.WHITE); |
||||
|
||||
met_name.setPrimaryColor(Color.LTGRAY); |
||||
|
||||
met_name.setFocusFraction(1.0f); |
||||
|
||||
met_name.setMetHintTextColor(Color.LTGRAY); |
||||
|
||||
met_name.setUnderlineColor(Color.LTGRAY); |
||||
} |
||||
} |
||||
|
||||
public static class MyPagerAdapter extends FragmentPagerAdapter { |
||||
private final String[] mTitle; |
||||
private final List<Fragment> mFragments; |
||||
|
||||
public MyPagerAdapter(@NonNull FragmentManager fm, String[] mTitle, List<Fragment> lists) { |
||||
super(fm); |
||||
this.mTitle = mTitle; |
||||
this.mFragments = lists; |
||||
} |
||||
|
||||
@NonNull |
||||
@Override |
||||
public Fragment getItem(int position) { |
||||
return mFragments.get(position); |
||||
} |
||||
|
||||
@Nullable |
||||
@Override |
||||
public CharSequence getPageTitle(int position) { |
||||
return mTitle[position]; |
||||
} |
||||
|
||||
@Override |
||||
public int getCount() { |
||||
return mFragments != null && mFragments.size() == 0 ? 0 : mFragments.size(); |
||||
} |
||||
} |
||||
|
||||
public Fragment getViewPagerFragment(int viewId, int index) { |
||||
String tag = "android:switcher:" + viewId + ":" + index; |
||||
return getChildFragmentManager().findFragmentByTag(tag); |
||||
} |
||||
|
||||
public static Fragment newInstance(Bundle args) { |
||||
CoordinateSystemContainerFragment fragment = new CoordinateSystemContainerFragment(); |
||||
fragment.setArguments(args); |
||||
return fragment; |
||||
} |
||||
} |
Loading…
Reference in new issue