use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.
the class SexyTopoActivity method restoreAutosave.
protected void restoreAutosave(String name) {
try {
Survey survey = Loader.restoreAutosave(SexyTopoActivity.this, name);
getSurveyManager().setCurrentSurvey(survey);
showSimpleToast(getString(R.string.restored));
} catch (Exception exception) {
showException(exception);
}
}
use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.
the class SexyTopoActivity method exportSurvey.
@SuppressLint("UnusedDeclaration")
public void exportSurvey() {
// public due to stupid Reflection requirements
final Survey survey = getSurvey();
AlertDialog.Builder builderSingle = new AlertDialog.Builder(this);
builderSingle.setTitle(getString(R.string.select_export_type));
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.select_dialog_item);
final Map<String, Exporter> nameToExporter = new HashMap<>();
for (Exporter exporter : SelectableExporters.EXPORTERS) {
String name = exporter.getExportTypeName(this);
arrayAdapter.add(name);
nameToExporter.put(name, exporter);
}
builderSingle.setNegativeButton(getString(R.string.cancel), (dialog, which) -> dialog.dismiss());
builderSingle.setAdapter(arrayAdapter, (dialog, which) -> {
String name = arrayAdapter.getItem(which);
Exporter selectedExporter = nameToExporter.get(name);
try {
assert selectedExporter != null;
selectedExporter.export(SexyTopoActivity.this, survey);
showSimpleToast(survey.getName() + " " + getString(R.string.export_successful));
} catch (Exception exception) {
showException(exception);
}
});
builderSingle.show();
}
use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.
the class SexyTopoActivity method loadSurvey.
protected void loadSurvey(String surveyName) {
try {
Log.d("Loading <i>" + surveyName + "</i>...");
Survey survey = Loader.loadSurvey(SexyTopoActivity.this, surveyName);
getSurveyManager().setCurrentSurvey(survey);
updateRememberedSurvey();
startActivity(PlanActivity.class);
Log.d("Loaded");
showSimpleToast(getString(R.string.loaded) + " " + surveyName);
} catch (Exception exception) {
showException(exception);
}
}
use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.
the class SexyTopoActivity method unlinkSurvey.
public void unlinkSurvey(final Station station) {
try {
Survey survey = getSurvey();
Set<SurveyConnection> linked = survey.getConnectedSurveys().get(station);
if (linked == null || linked.size() < 1) {
throw new Exception("Can't find any surveys to unlink");
} else if (linked.size() == 1) {
SurveyConnection onlyConnection = linked.iterator().next();
unlinkSurveyConnection(survey, station, onlyConnection.otherSurvey, onlyConnection.stationInOtherSurvey);
} else {
chooseSurveyToUnlink(survey, station);
}
} catch (Exception exception) {
showSimpleToast("Error unlinking survey: " + exception.getMessage());
showException(exception);
}
}
use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.
the class SexyTopoActivity method chooseSurveyToUnlink.
private void chooseSurveyToUnlink(final Survey survey, final Station station) {
AlertDialog.Builder builderSingle = new AlertDialog.Builder(this);
builderSingle.setTitle(getString(R.string.unlink_survey));
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.select_dialog_item);
final Set<SurveyConnection> connections = survey.getSurveysConnectedTo(station);
for (SurveyConnection connection : connections) {
arrayAdapter.add(connection.otherSurvey.getName());
}
builderSingle.setNegativeButton(getString(R.string.cancel), (dialog, which) -> dialog.dismiss());
builderSingle.setAdapter(arrayAdapter, (dialog, which) -> {
String surveyName = arrayAdapter.getItem(which);
try {
for (SurveyConnection connection : connections) {
if (connection.otherSurvey.getName().equals(surveyName)) {
Survey to = connection.otherSurvey;
Station stationTo = connection.stationInOtherSurvey;
unlinkSurveyConnection(survey, station, to, stationTo);
return;
}
}
throw new Exception("Couldn't find linked survey");
} catch (Exception exception) {
showException(exception);
}
});
builderSingle.show();
}
Aggregations