Search in sources :

Example 6 with Survey

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

the class GraphView method showContextMenu.

private void showContextMenu(MotionEvent event, final Station station) {
    OnClickListener listener = view -> {
        int id = view.getId();
        // because IDs are no longer final
        if (id == R.id.graph_station_select) {
            setActiveStation(station);
            invalidate();
        } else if (id == R.id.graph_station_toggle_left_right) {
            Direction newDirection = station.getExtendedElevationDirection().opposite();
            SurveyUpdater.setDirectionOfSubtree(station, newDirection);
            broadcastSurveyUpdated();
            invalidate();
        } else if (id == R.id.graph_station_comment) {
            openCommentDialog(station);
        } else if (id == R.id.graph_station_reverse) {
            SurveyUpdater.reverseLeg(survey, station);
            broadcastSurveyUpdated();
            invalidate();
        } else if (id == R.id.graph_station_delete) {
            askAboutDeletingStation(station);
            invalidate();
        } else if (id == R.id.graph_station_new_cross_section) {
            setActiveStation(station);
            setSketchTool(SketchTool.POSITION_CROSS_SECTION);
            activity.showSimpleToast(R.string.position_cross_section_instruction);
        } else if (id == R.id.graph_station_jump_to_table) {
            activity.jumpToStation(station, TableActivity.class);
        } else if (id == R.id.graph_station_jump_to_plan) {
            activity.jumpToStation(station, PlanActivity.class);
        } else if (id == R.id.graph_station_jump_to_ee) {
            activity.jumpToStation(station, ExtendedElevationActivity.class);
        } else if (id == R.id.graph_station_start_new_survey) {
            if (!survey.isSaved()) {
                activity.showSimpleToast(R.string.cannot_extend_unsaved_survey);
            }
            activity.continueSurvey(station);
        } else if (id == R.id.graph_station_unlink_survey) {
            activity.unlinkSurvey(station);
        }
    };
    PopupWindow menu = activity.getContextMenu(station, listener);
    View unlinkSurveyButton = menu.getContentView().findViewById(R.id.graph_station_unlink_survey);
    unlinkSurveyButton.setEnabled(survey.hasLinkedSurveys(station));
    View commentButton = menu.getContentView().findViewById(R.id.graph_station_comment);
    commentButton.setEnabled(station != survey.getOrigin());
    menu.showAtLocation(this, Gravity.START | Gravity.TOP, (int) (event.getX()), (int) (event.getY()));
}
Also used : Rect(android.graphics.Rect) WindowManager(android.view.WindowManager) R(org.hwyl.sexytopo.R) Colour(org.hwyl.sexytopo.model.sketch.Colour) GraphActivity(org.hwyl.sexytopo.control.activity.GraphActivity) AttributeSet(android.util.AttributeSet) Map(java.util.Map) View(android.view.View) Canvas(android.graphics.Canvas) SketchDetail(org.hwyl.sexytopo.model.sketch.SketchDetail) SymbolDetail(org.hwyl.sexytopo.model.sketch.SymbolDetail) Projection2D(org.hwyl.sexytopo.model.graph.Projection2D) TextTools(org.hwyl.sexytopo.control.util.TextTools) CrossSection(org.hwyl.sexytopo.model.sketch.CrossSection) TableActivity(org.hwyl.sexytopo.control.activity.TableActivity) Set(java.util.Set) SketchTool(org.hwyl.sexytopo.model.sketch.SketchTool) ScaleGestureDetector(android.view.ScaleGestureDetector) Direction(org.hwyl.sexytopo.model.graph.Direction) AlertDialog(android.app.AlertDialog) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) List(java.util.List) SurveyManager(org.hwyl.sexytopo.control.SurveyManager) CrossSectioner(org.hwyl.sexytopo.control.util.CrossSectioner) Symbol(org.hwyl.sexytopo.model.sketch.Symbol) Paint(android.graphics.Paint) Context(android.content.Context) Path(android.graphics.Path) GestureDetector(android.view.GestureDetector) PlanActivity(org.hwyl.sexytopo.control.activity.PlanActivity) SurveyConnection(org.hwyl.sexytopo.model.survey.SurveyConnection) BitmapFactory(android.graphics.BitmapFactory) HashMap(java.util.HashMap) Station(org.hwyl.sexytopo.model.survey.Station) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) SurveyUpdater(org.hwyl.sexytopo.control.util.SurveyUpdater) MotionEvent(android.view.MotionEvent) Line(org.hwyl.sexytopo.model.graph.Line) CrossSectionDetail(org.hwyl.sexytopo.model.sketch.CrossSectionDetail) Leg(org.hwyl.sexytopo.model.survey.Leg) Survey(org.hwyl.sexytopo.model.survey.Survey) PreferenceAccess(org.hwyl.sexytopo.control.util.PreferenceAccess) Space2DUtils(org.hwyl.sexytopo.control.util.Space2DUtils) PopupWindow(android.widget.PopupWindow) Log(org.hwyl.sexytopo.control.Log) BrushColour(org.hwyl.sexytopo.model.sketch.BrushColour) ExtendedElevationActivity(org.hwyl.sexytopo.control.activity.ExtendedElevationActivity) SurveyStats(org.hwyl.sexytopo.control.util.SurveyStats) Space(org.hwyl.sexytopo.model.graph.Space) TextDetail(org.hwyl.sexytopo.model.sketch.TextDetail) Gravity(android.view.Gravity) PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) Sketch(org.hwyl.sexytopo.model.sketch.Sketch) SharedPreferences(android.content.SharedPreferences) CohenSutherlandAlgorithm(org.hwyl.sexytopo.control.util.CohenSutherlandAlgorithm) Bitmap(android.graphics.Bitmap) EditText(android.widget.EditText) TableActivity(org.hwyl.sexytopo.control.activity.TableActivity) PopupWindow(android.widget.PopupWindow) ExtendedElevationActivity(org.hwyl.sexytopo.control.activity.ExtendedElevationActivity) Direction(org.hwyl.sexytopo.model.graph.Direction) View(android.view.View)

Example 7 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), (dialog, which) -> dialog.dismiss());
    builderSingle.setAdapter(arrayAdapter, (dialog, 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 : Station(org.hwyl.sexytopo.model.survey.Station) AlertDialog(android.app.AlertDialog) Survey(org.hwyl.sexytopo.model.survey.Survey) ArrayAdapter(android.widget.ArrayAdapter)

Example 8 with Survey

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

the class StatsActivity method updateStats.

private void updateStats() {
    Survey survey = getSurvey();
    float length = SurveyStats.calcTotalLength(survey);
    setStatsField(R.id.statsFieldLength, TextTools.formatTo2dpWithComma(length));
    float heightRange = SurveyStats.calcHeightRange(survey);
    setStatsField(R.id.statsFieldDepth, TextTools.formatTo2dpWithComma(heightRange));
    int numberOfStations = SurveyStats.calcNumberStations(survey);
    setStatsField(R.id.statsFieldNumberStations, TextTools.formatWithComma(numberOfStations));
    int numberOfLegs = SurveyStats.calcNumberSubFullLegs(survey.getOrigin());
    setStatsField(R.id.statsFieldNumberLegs, TextTools.formatWithComma(numberOfLegs));
    int numberOfSplays = SurveyStats.calcNumberSubSplays(survey.getOrigin());
    setStatsField(R.id.statsFieldNumberSplays, TextTools.formatWithComma(numberOfSplays));
    float shortestLeg = SurveyStats.calcShortestLeg(survey);
    setStatsField(R.id.statsFieldShortestLeg, TextTools.formatTo2dpWithComma(shortestLeg));
    float longestLeg = SurveyStats.calcLongestLeg(survey);
    setStatsField(R.id.statsFieldLongestLeg, TextTools.formatTo2dpWithComma(longestLeg));
}
Also used : Survey(org.hwyl.sexytopo.model.survey.Survey)

Example 9 with Survey

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

the class TableActivity method askAboutDeleting.

/*
        This method is a bit convoluted but reflects the UI choices.

        We are either deleting a splay or a leg (if we are deleting a station,
        we still have to delete the source leg). If the latter, we are also deleting any
        onward survey from the station.

        If leg is null, we are deleting the station
        If leg is not null, we are only deleting the leg from the specified station
     */
public void askAboutDeleting(Context context, final Station station, final Leg leg) {
    int numFullLegsToBeDeleted = 0;
    int numSplaysToBeDeleted = 0;
    final boolean deletingLeg = leg != null;
    boolean deletingSplay = (deletingLeg && !leg.hasDestination());
    if (deletingSplay) {
        numSplaysToBeDeleted += 1;
    } else {
        numFullLegsToBeDeleted++;
        Station root = deletingLeg ? leg.getDestination() : station;
        numFullLegsToBeDeleted += SurveyStats.calcNumberSubFullLegs(root);
        numSplaysToBeDeleted += SurveyStats.calcNumberSubSplays(root);
    }
    String message = context.getString(R.string.this_will_delete);
    if (numFullLegsToBeDeleted > 0) {
        String noun = context.getString(R.string.leg).toLowerCase();
        message += "\n" + TextTools.pluralise(numFullLegsToBeDeleted, noun);
        noun = context.getString(R.string.station).toLowerCase();
        message += " (" + TextTools.pluralise(numFullLegsToBeDeleted, noun) + ")";
    }
    if (numSplaysToBeDeleted > 0) {
        String noun = context.getString(R.string.splay).toLowerCase();
        message += "\n" + TextTools.pluralise(numSplaysToBeDeleted, noun);
    }
    new AlertDialog.Builder(context).setMessage(message).setPositiveButton(R.string.delete, (dialog, which) -> {
        Survey survey = getSurvey();
        if (deletingLeg) {
            SurveyUpdater.deleteSplay(survey, station, leg);
        } else {
            SurveyUpdater.deleteStation(survey, station);
        }
        getSurveyManager().broadcastSurveyUpdated();
    }).setNegativeButton(R.string.cancel, null).show();
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey) SuppressLint(android.annotation.SuppressLint)

Example 10 with Survey

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

the class Loader method loadSurvey.

public static Survey loadSurvey(Context context, String name, Set<String> surveyNamesNotToLoad, boolean restoreAutosave) throws Exception {
    Survey survey = new Survey(name);
    loadSurveyData(context, name, survey, restoreAutosave);
    loadSketches(context, survey, restoreAutosave);
    surveyNamesNotToLoad.add(name);
    loadMetadata(context, survey, surveyNamesNotToLoad, restoreAutosave);
    survey.setSaved(true);
    return survey;
}
Also used : Survey(org.hwyl.sexytopo.model.survey.Survey)

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