Search in sources :

Example 1 with Survey

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

Example 2 with Survey

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

Example 3 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.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();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) 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)

Example 4 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.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 5 with Survey

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

Aggregations

Survey (org.hwyl.sexytopo.model.survey.Survey)66 Test (org.junit.Test)32 Station (org.hwyl.sexytopo.model.survey.Station)16 Leg (org.hwyl.sexytopo.model.survey.Leg)12 AlertDialog (android.app.AlertDialog)9 DialogInterface (android.content.DialogInterface)9 ArrayAdapter (android.widget.ArrayAdapter)6 Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)6 Sketch (org.hwyl.sexytopo.model.sketch.Sketch)6 Matchers.anyString (org.mockito.Matchers.anyString)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 File (java.io.File)4 Space (org.hwyl.sexytopo.model.graph.Space)4 Editable (android.text.Editable)3 EditText (android.widget.EditText)3 HashMap (java.util.HashMap)3 GraphActivity (org.hwyl.sexytopo.control.activity.GraphActivity)3 PlanActivity (org.hwyl.sexytopo.control.activity.PlanActivity)3 SurveyConnection (org.hwyl.sexytopo.model.survey.SurveyConnection)3 Intent (android.content.Intent)1