use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.
the class SexyTopoActivity method continueSurvey.
public void continueSurvey(final Station joinPoint) {
final Survey currentSurvey = getSurvey();
if (!currentSurvey.isSaved()) {
showSimpleToast(R.string.cannot_extend_unsaved_survey);
return;
}
final EditText input = new EditText(this);
String defaultName = Util.getNextAvailableName(this, currentSurvey.getName());
input.setText(defaultName);
new AlertDialog.Builder(this).setTitle(getString(R.string.dialog_new_survey_title)).setView(input).setPositiveButton(getString(R.string.ok), (dialog, whichButton) -> {
Editable value = input.getText();
String name = value.toString();
if (Util.isSurveyNameUnique(SexyTopoActivity.this, name)) {
Survey newSurvey = new Survey(name);
newSurvey.getOrigin().setName(joinPoint.getName());
joinSurveys(currentSurvey, joinPoint, newSurvey, newSurvey.getOrigin());
setSurvey(newSurvey);
} else {
showSimpleToast(R.string.dialog_new_survey_name_must_be_unique);
}
}).setNegativeButton(getString(R.string.cancel), (dialog, whichButton) -> {
/* Do nothing. */
}).show();
}
use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.
the class SexyTopoActivity method linkExistingSurvey.
@SuppressLint("UnusedDeclaration")
public void linkExistingSurvey() {
// public due to stupid Reflection requirements
File[] surveyDirectories = Util.getSurveyDirectories(this);
if (surveyDirectories.length == 0) {
showSimpleToast(getString(R.string.no_surveys));
return;
}
AlertDialog.Builder builderSingle = new AlertDialog.Builder(this);
builderSingle.setTitle(getString(R.string.link_survey));
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.select_dialog_item);
for (File file : surveyDirectories) {
arrayAdapter.add(file.getName());
}
builderSingle.setNegativeButton(getString(R.string.cancel), (dialog, which) -> dialog.dismiss());
builderSingle.setAdapter(arrayAdapter, (dialog, which) -> {
String surveyName = arrayAdapter.getItem(which);
try {
Survey surveyToLink = Loader.loadSurvey(SexyTopoActivity.this, surveyName);
linkToStationInSurvey(surveyToLink);
} catch (Exception exception) {
showException(exception);
}
});
builderSingle.show();
}
use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.
the class SexyTopoActivity method generateTestSurvey.
private void generateTestSurvey() {
new AlertDialog.Builder(this).setTitle("Generate Test Data").setMessage("Replace the existing survey with randomly-generated data?").setCancelable(false).setPositiveButton("Replace", (dialog, id) -> {
try {
Survey currentSurvey = TestSurveyCreator.create(getSurvey().getName(), 10, 5);
setSurvey(currentSurvey);
} catch (Exception exception) {
showException(exception);
}
}).setNegativeButton(getString(R.string.cancel), null).show();
}
use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.
the class SexyTopoActivity method importSurvey.
@SuppressLint("UnusedDeclaration")
public void importSurvey() {
// public due to stupid Reflection requirements
File[] importFiles = Util.getImportFiles(this);
if (importFiles.length == 0) {
showSimpleToast(getString(R.string.no_imports));
return;
}
final Map<String, File> nameToFiles = new HashMap<>();
for (File file : importFiles) {
nameToFiles.put(file.getName(), file);
}
AlertDialog.Builder builderSingle = new AlertDialog.Builder(this);
builderSingle.setTitle(R.string.import_survey);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.select_dialog_item);
arrayAdapter.addAll(nameToFiles.keySet());
builderSingle.setNegativeButton(getString(R.string.cancel), (dialog, which) -> dialog.dismiss());
builderSingle.setAdapter(arrayAdapter, (dialog, which) -> {
File file = nameToFiles.get(arrayAdapter.getItem(which));
try {
Survey survey = ImportManager.toSurvey(file);
if (Util.doesSurveyExist(SexyTopoActivity.this, survey.getName())) {
confirmToProceed(R.string.continue_question, R.string.survey_already_exists, R.string.replace, R.string.cancel, "saveImportedSurvey", survey, file);
} else {
saveImportedSurvey(survey, file);
}
} catch (Exception exception) {
showException(exception);
}
});
builderSingle.show();
}
use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.
the class StatsActivity method updateLinkedStats.
private void updateLinkedStats() {
Set<Survey> surveys = getSurvey().getRecursiveConnectedSurveys();
surveys.add(getSurvey());
int numberSurveys = surveys.size();
TableLayout tableLayout = findViewById(R.id.statsAllLinkedSurveys);
if (numberSurveys <= 1) {
tableLayout.setVisibility(View.GONE);
} else {
tableLayout.setVisibility(View.VISIBLE);
}
float length = 0;
float lowestHeight = Float.POSITIVE_INFINITY;
float highestHeight = Float.NEGATIVE_INFINITY;
int numberOfStations = 0;
int numberOfLegs = 0;
int numberOfSplays = 0;
float shortestLeg = Float.POSITIVE_INFINITY;
float longestLeg = 0;
for (Survey survey : surveys) {
length += SurveyStats.calcTotalLength(survey);
float[] heightRange = SurveyStats.calcHeightRangeArray(survey);
lowestHeight = Math.min(heightRange[0], lowestHeight);
highestHeight = Math.max(heightRange[1], highestHeight);
numberOfStations += SurveyStats.calcNumberStations(survey);
numberOfLegs = SurveyStats.calcNumberSubFullLegs(survey.getOrigin());
numberOfSplays += SurveyStats.calcNumberSubSplays(survey.getOrigin());
longestLeg = Math.max(longestLeg, SurveyStats.calcLongestLeg(survey));
shortestLeg = Math.min(shortestLeg, SurveyStats.calcShortestLeg(survey));
}
float heightRange = highestHeight - lowestHeight;
if (Float.isInfinite(heightRange)) {
heightRange = 0;
}
if (Float.isInfinite(shortestLeg)) {
shortestLeg = 0;
}
setStatsField(R.id.statsFieldNumberLinkedSurveys, TextTools.formatWithComma(numberSurveys));
setStatsField(R.id.statsFieldLinkedLength, TextTools.formatTo2dpWithComma(length));
setStatsField(R.id.statsFieldLinkedDepth, TextTools.formatTo2dpWithComma(heightRange));
setStatsField(R.id.statsFieldLinkedNumberStations, TextTools.formatWithComma(numberOfStations));
setStatsField(R.id.statsFieldLinkedNumberLegs, TextTools.formatWithComma(numberOfLegs));
setStatsField(R.id.statsFieldLinkedNumberSplays, TextTools.formatWithComma(numberOfSplays));
setStatsField(R.id.statsFieldLinkedShortestLeg, TextTools.formatTo2dpWithComma(shortestLeg));
setStatsField(R.id.statsFieldLinkedLongestLeg, TextTools.formatTo2dpWithComma(longestLeg));
}
Aggregations