Search in sources :

Example 66 with Survey

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

the class TableActivity method syncTableWithSurvey.

public void syncTableWithSurvey() {
    Survey survey = getSurvey();
    stationsToTableIndex.clear();
    List<GraphToListTranslator.SurveyListEntry> tableEntries = graphToListTranslator.toChronoListOfSurveyListEntries(survey);
    if (tableEntries.size() == 0) {
        Toast.makeText(getApplicationContext(), R.string.no_data, Toast.LENGTH_SHORT).show();
    }
    final TableLayout tableLayout = findViewById(R.id.BodyTable);
    tableLayout.removeAllViews();
    for (GraphToListTranslator.SurveyListEntry entry : tableEntries) {
        TableRow tableRow = (TableRow) LayoutInflater.from(this).inflate(R.layout.table_row, null);
        final Map<TableCol, Object> map = GraphToListTranslator.createMap(entry);
        for (TableCol col : TableCol.values()) {
            if (col == TableCol.COMMENT) {
                continue;
            }
            String display = map.containsKey(col) ? col.format(map.get(col)) : "?";
            int id = TABLE_COL_BY_ANDROID_ID.get(col);
            TextView textView = tableRow.findViewById(id);
            textView.setText(display);
            if (isActiveStation(map.get(col))) {
                textView.setBackgroundColor(GraphView.HIGHLIGHT_COLOUR.intValue);
            }
            if (entry.getLeg().hasDestination()) {
                textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
            } else {
                textView.setTypeface(textView.getTypeface(), Typeface.NORMAL);
            }
            fieldToSurveyEntry.put(textView, entry);
            fieldToTableCol.put(textView, col);
            textView.setOnLongClickListener(this);
        }
        int rowCount = tableLayout.getChildCount();
        tableLayout.addView(tableRow, rowCount);
        if (entry.getLeg().hasDestination()) {
            Station to = entry.getLeg().getDestination();
            stationsToTableIndex.put(to, rowCount);
        }
    }
    tableLayout.requestLayout();
}
Also used : TableCol(org.hwyl.sexytopo.model.table.TableCol) SuppressLint(android.annotation.SuppressLint) Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey) GraphToListTranslator(org.hwyl.sexytopo.control.util.GraphToListTranslator) TableRow(android.widget.TableRow) TextView(android.widget.TextView) TableLayout(android.widget.TableLayout)

Example 67 with Survey

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

the class GraphActivity method syncGraphWithSurvey.

private void syncGraphWithSurvey() {
    Survey survey = getSurvey();
    graphView.setSurvey(survey);
    graphView.setSketch(getSketch(survey));
    graphView.setProjection(getProjection(survey));
    graphView.checkForChangedSurvey();
    float surveyLength = SurveyStats.calcTotalLength(survey);
    float surveyHeight = SurveyStats.calcHeightRange(survey);
    graphView.setCachedStats(surveyLength, surveyHeight);
    graphView.invalidate();
}
Also used : Survey(org.hwyl.sexytopo.model.survey.Survey)

Example 68 with Survey

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

the class SurvexImporter method toSurvey.

@Override
public Survey toSurvey(File file) throws Exception {
    String text = Loader.slurpFile(file.getAbsolutePath());
    Survey survey = new Survey(getDefaultName(file));
    parse(text, survey);
    return survey;
}
Also used : Survey(org.hwyl.sexytopo.model.survey.Survey)

Example 69 with Survey

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

the class ManualEntry method renameStation.

public static void renameStation(final TableActivity activity, final Survey survey, final Station toRename) {
    final EditText renameField = new EditText(activity);
    renameField.setText(toRename.getName());
    renameField.addTextChangedListener(new TextWatcher() {

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        // nothing
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // nothing
        }

        public void afterTextChanged(Editable s) {
            String currentName = toRename.getName();
            String currentText = renameField.getText().toString();
            // only check for non-null or max length
            if (currentText.isEmpty()) {
                renameField.setError("Cannot be blank");
            } else if (currentText.equals("-")) {
                renameField.setError("Station cannot be named \"-\"");
            } else if (!currentText.equals(currentName) && (survey.getStationByName(currentText) != null)) {
                renameField.setError("Station name must be unique");
            } else {
                renameField.setError(null);
            }
        }
    });
    AlertDialog dialog = new AlertDialog.Builder(activity).setTitle("Edit name").setView(renameField).setPositiveButton("Rename", (ignore, buttonId) -> {
        String newName = renameField.getText().toString();
        try {
            SurveyUpdater.renameStation(survey, toRename, newName);
            activity.syncTableWithSurvey();
        } catch (Exception e) {
            activity.showSimpleToast("Rename failed");
        }
    }).setNegativeButton("Cancel", (ignore, buttonId) -> {
    /* Do nothing */
    }).create();
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    dialog.show();
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) Leg(org.hwyl.sexytopo.model.survey.Leg) Survey(org.hwyl.sexytopo.model.survey.Survey) LayoutInflater(android.view.LayoutInflater) TableActivity(org.hwyl.sexytopo.control.activity.TableActivity) WindowManager(android.view.WindowManager) Dialog(android.app.Dialog) R(org.hwyl.sexytopo.R) Station(org.hwyl.sexytopo.model.survey.Station) Editable(android.text.Editable) AlertDialog(android.app.AlertDialog) LRUD(org.hwyl.sexytopo.model.table.LRUD) TextView(android.widget.TextView) SurveyUpdater(org.hwyl.sexytopo.control.util.SurveyUpdater) SurveyManager(org.hwyl.sexytopo.control.SurveyManager) View(android.view.View) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) TextWatcher(android.text.TextWatcher) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable)

Example 70 with Survey

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

the class TherionImporter method toSurvey.

public Survey toSurvey(File directory) throws Exception {
    Survey survey = null;
    for (File file : directory.listFiles()) {
        if (file.getName().endsWith("th")) {
            survey = parseTh(file);
        } else if (file.getName().endsWith("xvi")) {
            String filenameNoExtension = FilenameUtils.removeExtension(file.getName());
            if (filenameNoExtension.endsWith(SexyTopo.PLAN_SUFFIX)) {
                Sketch sketch = XviImporter.getSketch(file);
                survey.setPlanSketch(sketch);
            } else if (filenameNoExtension.endsWith(SexyTopo.EE_SUFFIX)) {
                Sketch sketch = XviImporter.getSketch(file);
                survey.setElevationSketch(sketch);
            }
        }
    }
    return survey;
}
Also used : Survey(org.hwyl.sexytopo.model.survey.Survey) Sketch(org.hwyl.sexytopo.model.sketch.Sketch) File(java.io.File)

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