Search in sources :

Example 61 with Survey

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();
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) Arrays(java.util.Arrays) Bundle(android.os.Bundle) Communicator(org.hwyl.sexytopo.comms.Communicator) PackageManager(android.content.pm.PackageManager) TestSurveyCreator(org.hwyl.sexytopo.demo.TestSurveyCreator) R(org.hwyl.sexytopo.R) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) InputMode(org.hwyl.sexytopo.control.util.InputMode) Manifest(android.Manifest) Exporter(org.hwyl.sexytopo.control.io.translation.Exporter) SexyTopo(org.hwyl.sexytopo.SexyTopo) Map(java.util.Map) ActivityInfo(android.content.pm.ActivityInfo) View(android.view.View) PreferenceManager(android.preference.PreferenceManager) Method(java.lang.reflect.Method) ContextCompat(androidx.core.content.ContextCompat) AsyncTask(android.os.AsyncTask) Set(java.util.Set) SubMenu(android.view.SubMenu) AlertDialog(android.app.AlertDialog) List(java.util.List) SurveyManager(org.hwyl.sexytopo.control.SurveyManager) Saver(org.hwyl.sexytopo.control.io.basic.Saver) Context(android.content.Context) NullCommunicator(org.hwyl.sexytopo.comms.missing.NullCommunicator) SurveyConnection(org.hwyl.sexytopo.model.survey.SurveyConnection) Instrument(org.hwyl.sexytopo.comms.Instrument) Intent(android.content.Intent) HashMap(java.util.HashMap) Station(org.hwyl.sexytopo.model.survey.Station) PackageInfo(android.content.pm.PackageInfo) Editable(android.text.Editable) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) Toast(android.widget.Toast) Menu(android.view.Menu) SelectableExporters(org.hwyl.sexytopo.control.io.translation.SelectableExporters) Build(android.os.Build) Survey(org.hwyl.sexytopo.model.survey.Survey) ActivityCompat(androidx.core.app.ActivityCompat) Log(org.hwyl.sexytopo.control.Log) FirebaseCrashlytics(com.google.firebase.crashlytics.FirebaseCrashlytics) Loader(org.hwyl.sexytopo.control.io.basic.Loader) File(java.io.File) ArrayAdapter(android.widget.ArrayAdapter) SharedPreferences(android.content.SharedPreferences) ImportManager(org.hwyl.sexytopo.control.io.translation.ImportManager) Util(org.hwyl.sexytopo.control.io.Util) EditText(android.widget.EditText) Survey(org.hwyl.sexytopo.model.survey.Survey) Editable(android.text.Editable)

Example 62 with Survey

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();
}
Also used : AlertDialog(android.app.AlertDialog) Survey(org.hwyl.sexytopo.model.survey.Survey) File(java.io.File) ArrayAdapter(android.widget.ArrayAdapter) SuppressLint(android.annotation.SuppressLint)

Example 63 with Survey

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();
}
Also used : Survey(org.hwyl.sexytopo.model.survey.Survey)

Example 64 with Survey

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();
}
Also used : AlertDialog(android.app.AlertDialog) Survey(org.hwyl.sexytopo.model.survey.Survey) HashMap(java.util.HashMap) File(java.io.File) ArrayAdapter(android.widget.ArrayAdapter) SuppressLint(android.annotation.SuppressLint)

Example 65 with Survey

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));
}
Also used : Survey(org.hwyl.sexytopo.model.survey.Survey) TableLayout(android.widget.TableLayout)

Aggregations

Survey (org.hwyl.sexytopo.model.survey.Survey)101 Test (org.junit.Test)56 Station (org.hwyl.sexytopo.model.survey.Station)31 Leg (org.hwyl.sexytopo.model.survey.Leg)24 AlertDialog (android.app.AlertDialog)10 SuppressLint (android.annotation.SuppressLint)9 Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)9 ArrayAdapter (android.widget.ArrayAdapter)8 File (java.io.File)6 HashMap (java.util.HashMap)6 View (android.view.View)5 EditText (android.widget.EditText)5 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 Context (android.content.Context)4 SharedPreferences (android.content.SharedPreferences)4 Editable (android.text.Editable)4 List (java.util.List)4 Map (java.util.Map)4 R (org.hwyl.sexytopo.R)4