Search in sources :

Example 11 with Survey

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

Example 12 with Survey

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

Example 13 with Survey

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

Example 14 with Survey

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

Example 15 with Survey

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

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