Skip to content

Commit

Permalink
GeoTrace: Add a selection spinner for the accuracy threshold.
Browse files Browse the repository at this point in the history
  • Loading branch information
zestyping committed Feb 19, 2019
1 parent d886925 commit cb88981
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class GeoTraceActivity extends BaseGeoMapActivity implements IRegisterRec
public static final String RECORDING_ACTIVE_KEY = "recording_active";
public static final String RECORDING_MODE_KEY = "recording_mode";
public static final String INTERVAL_INDEX_KEY = "interval_index";
public static final String ACCURACY_THRESHOLD_INDEX_KEY = "accuracy_threshold_index";

private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
private ScheduledFuture schedulerHandler;
Expand Down Expand Up @@ -84,13 +85,19 @@ public class GeoTraceActivity extends BaseGeoMapActivity implements IRegisterRec
private final int MANUAL_RECORDING = 0;
private final int AUTOMATIC_RECORDING = 1;

private final int[] ACCURACY_THRESHOLD_OPTIONS = {
0, 3, 5, 10, 15, 20
};
private final int DEFAULT_ACCURACY_THRESHOLD_INDEX = 3; // default is 10 meters

private boolean recordingActive;
private int recordingMode; // 0 manual, 1 is automatic
private RadioGroup radioGroup;
private View autoOptions;
private Spinner autoInterval;
private int intervalIndex = DEFAULT_INTERVAL_INDEX;
private double accuracyThreshold = -1;
private Spinner accuracyThreshold;
private int accuracyThresholdIndex = DEFAULT_ACCURACY_THRESHOLD_INDEX;

// restored from savedInstanceState
private MapPoint restoredMapCenter;
Expand All @@ -106,6 +113,8 @@ public class GeoTraceActivity extends BaseGeoMapActivity implements IRegisterRec
recordingActive = savedInstanceState.getBoolean(RECORDING_ACTIVE_KEY, false);
recordingMode = savedInstanceState.getInt(RECORDING_MODE_KEY, MANUAL_RECORDING);
intervalIndex = savedInstanceState.getInt(INTERVAL_INDEX_KEY, DEFAULT_INTERVAL_INDEX);
accuracyThresholdIndex = savedInstanceState.getInt(
ACCURACY_THRESHOLD_INDEX_KEY, DEFAULT_ACCURACY_THRESHOLD_INDEX);
}

if (!areLocationPermissionsGranted(this)) {
Expand Down Expand Up @@ -164,6 +173,7 @@ public MapFragment createMapFragment() {
state.putBoolean(RECORDING_ACTIVE_KEY, recordingActive);
state.putInt(RECORDING_MODE_KEY, recordingMode);
state.putInt(INTERVAL_INDEX_KEY, intervalIndex);
state.putInt(ACCURACY_THRESHOLD_INDEX_KEY, accuracyThresholdIndex);
}

@Override protected void onDestroy() {
Expand Down Expand Up @@ -219,6 +229,24 @@ public void initMap(MapFragment newMapFragment) {
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
autoInterval.setAdapter(adapter);

accuracyThreshold = traceSettingsView.findViewById(R.id.accuracy_threshold);
accuracyThreshold.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
accuracyThresholdIndex = position;
}

@Override public void onNothingSelected(AdapterView<?> parent) { }
});

// Populate the accuracy_threshold spinner with the options in ACCURACY_THRESHOLD_OPTIONS.
options = new String[ACCURACY_THRESHOLD_OPTIONS.length];
for (int i = 0; i < ACCURACY_THRESHOLD_OPTIONS.length; i++) {
options[i] = formatAccuracyThreshold(ACCURACY_THRESHOLD_OPTIONS[i]);
}
adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, options);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
accuracyThreshold.setAdapter(adapter);

polygonOrPolylineView = getLayoutInflater().inflate(R.layout.polygon_polyline_dialog, null);

clearButton = findViewById(R.id.clear);
Expand Down Expand Up @@ -340,6 +368,13 @@ private String formatInterval(int seconds) {
getResources().getQuantityString(R.plurals.number_of_seconds, seconds, seconds);
}

/** Formats an entry in the accuracy threshold dropdown. */
private String formatAccuracyThreshold(int meters) {
return meters > 0 ?
getResources().getQuantityString(R.plurals.number_of_meters, meters, meters) :
getString(R.string.none);
}

/**
* Parses a form result string, as previously formatted by formatPoints,
* into a list of polyline vertices.
Expand Down Expand Up @@ -453,6 +488,7 @@ private void onGpsLocation(MapPoint point) {
private void appendPoint() {
MapPoint point = map.getGpsLocation();
if (point != null) {
int accuracyThreshold = ACCURACY_THRESHOLD_OPTIONS[accuracyThresholdIndex];
if (recordingMode == AUTOMATIC_RECORDING && accuracyThreshold > 0 &&
point.sd > accuracyThreshold) {
return;
Expand Down Expand Up @@ -496,6 +532,7 @@ private void updateUi() {
radioGroup.check(recordingMode == AUTOMATIC_RECORDING ? R.id.trace_automatic : R.id.trace_manual);
autoOptions.setVisibility((recordingMode == AUTOMATIC_RECORDING) ? View.VISIBLE : View.GONE);
autoInterval.setSelection(intervalIndex);
accuracyThreshold.setSelection(accuracyThresholdIndex);
}

private void showClearDialog() {
Expand Down
15 changes: 15 additions & 0 deletions collect_app/src/main/res/layout/geotrace_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="42dp"
android:text="@string/accuracy_requirement" />
<Spinner
android:id="@+id/accuracy_threshold"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

</LinearLayout>

</LinearLayout>
6 changes: 6 additions & 0 deletions collect_app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@
<item quantity="one">%d minute</item>
<item quantity="other">%d minutes</item>
</plurals>
<string name="accuracy_requirement">Accuracy requirement:</string>
<string name="none">None</string>
<plurals name="number_of_meters">
<item quantity="one">%d meter</item>
<item quantity="other">%d meters</item>
</plurals>
<string name="geoshape_instruction">Long press to place marks.</string>
<string name="geotrace_instruction">Wait for lock, then tap add marker button to start.</string>
<string name="geopoint_instruction">Long press to place mark or tap add marker button.</string>
Expand Down

0 comments on commit cb88981

Please sign in to comment.