Search in sources :

Example 56 with Survey

use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.

the class LoaderTest method testReversedLegIsParsed.

@Test
public void testReversedLegIsParsed() throws Exception {
    String text = "2\t1\t9.11\t121\t-23\n";
    Survey survey = new Survey("TestSurvey");
    Loader.parse(text, survey);
    assert survey.getAllStations().size() == 2;
    assert survey.getOrigin().getConnectedOnwardLegs().get(0).getDestination().getName().equals("2");
    assert survey.getOrigin().getConnectedOnwardLegs().get(0).wasShotBackwards();
}
Also used : Survey(org.hwyl.sexytopo.model.survey.Survey) Test(org.junit.Test)

Example 57 with Survey

use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.

the class LoaderTest method testSimpleSurveyIsParsed.

@Test
public void testSimpleSurveyIsParsed() throws Exception {
    String text = "1\t2\t9.11\t121\t-23\n";
    Survey survey = new Survey("TestSurvey");
    Loader.parse(text, survey);
    assert survey.getAllStations().size() == 2;
    assert survey.getOrigin().getConnectedOnwardLegs().get(0).getDestination().getName().equals("2");
}
Also used : Survey(org.hwyl.sexytopo.model.survey.Survey) Test(org.junit.Test)

Example 58 with Survey

use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.

the class LoaderTest method testEmptySurveyResultsIn1Station.

@Test
public void testEmptySurveyResultsIn1Station() throws Exception {
    String text = "";
    Survey survey = new Survey("TestSurvey");
    Loader.parse(text, survey);
    assert survey.getAllStations().size() == 1;
}
Also used : Survey(org.hwyl.sexytopo.model.survey.Survey) Test(org.junit.Test)

Example 59 with Survey

use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.

the class SexyTopoActivity method saveSurveyAsName.

private void saveSurveyAsName() {
    final EditText input = new EditText(this);
    input.setText(getSurvey().getName());
    input.setContentDescription("Enter new name");
    new AlertDialog.Builder(this).setTitle(getString(R.string.dialog_save_as_title)).setView(input).setPositiveButton(getString(R.string.ok), (dialog, whichButton) -> {
        Editable value = input.getText();
        String newName = value.toString();
        Survey survey = getSurvey();
        String oldName = survey.getName();
        if (oldName.equals(newName)) {
            return;
        }
        try {
            survey.setName(newName);
            if (!Util.isSurveyNameUnique(SexyTopoActivity.this, survey.getName())) {
                throw new Exception("Survey already exists");
            }
            Saver.save(SexyTopoActivity.this, survey);
            updateRememberedSurvey();
        } catch (Exception exception) {
            survey.setName(oldName);
            showSimpleToast(R.string.error_saving_survey);
            showException(exception);
        }
    }).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 60 with Survey

use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.

the class SexyTopoActivity method startNewSurvey.

public void startNewSurvey() {
    // public due to stupid Reflection requirements
    Log.d("Starting new survey");
    final EditText input = new EditText(this);
    String defaultName = Util.getNextDefaultSurveyName(this);
    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();
        Survey survey = new Survey(name);
        if (Util.isSurveyNameUnique(SexyTopoActivity.this, name)) {
            setSurvey(survey);
        } 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)

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