use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.
the class SexyTopoActivity method restoreAutosave.
private void restoreAutosave() {
try {
Survey survey = Loader.loadSurvey(SexyTopoActivity.this, getSurvey().getName());
SurveyManager.getInstance(SexyTopoActivity.this).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.
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), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String name = arrayAdapter.getItem(which);
Exporter selectedExporter = nameToExporter.get(name);
try {
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 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.getConnectedSurveys().get(station);
for (SurveyConnection connection : connections) {
arrayAdapter.add(connection.otherSurvey.getName());
}
builderSingle.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int 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();
}
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.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 linkToStationInSurvey.
private void linkToStationInSurvey(final Survey surveyToLink) {
final Station[] stations = surveyToLink.getAllStations().toArray(new Station[] {});
AlertDialog.Builder builderSingle = new AlertDialog.Builder(this);
builderSingle.setTitle(getString(R.string.link_survey_station));
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.select_dialog_item);
for (Station station : stations) {
arrayAdapter.add(station.getName());
}
builderSingle.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String stationName = arrayAdapter.getItem(which);
try {
Station selectedStation = Survey.NULL_STATION;
for (Station station : stations) {
if (station.getName().equals(stationName)) {
selectedStation = station;
break;
}
}
Survey current = getSurvey();
joinSurveys(current, current.getActiveStation(), surveyToLink, selectedStation);
} catch (Exception exception) {
showException(exception);
}
}
});
builderSingle.show();
}
Aggregations