Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V5.5/geonav #705

Merged
merged 19 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c89612c
Added simple fix quality to geonav log
chaneylc Aug 2, 2023
83efbfb
Replaced GeoNav Toggle with Dialog #690
chaneylc Aug 2, 2023
99ce473
Added precision threshold to GeoNav.
chaneylc Aug 3, 2023
5164bd4
Fix minor ui bug in gnss trait making user press disconnect twice.
chaneylc Aug 2, 2023
3b8e457
Updated field editor location based field switch snackbar to geonav's…
chaneylc Aug 3, 2023
841107d
Updated GNSS trait with user-choosable required fix.
chaneylc Aug 3, 2023
efa779d
Added fix to observation unit geo json properties
chaneylc Aug 4, 2023
80e4019
geonav changes for v5.5
chaneylc Aug 7, 2023
43d5d63
moved geonav/barcode search collect activity snackbar to top of the b…
chaneylc Aug 8, 2023
97121c0
fix field editor navigate to closest field snack message
chaneylc Aug 21, 2023
238a866
moved gps tracker to collect to persist data in gnss trait layout
chaneylc Aug 21, 2023
68eb5d0
updated connection check to skip when using internal gps
chaneylc Aug 21, 2023
edcdb31
right-aligned checkboxes in geonav collect settings dialog
chaneylc Aug 30, 2023
c963eff
fixed layout width warning
chaneylc Aug 30, 2023
ee6e7bb
aligned checkboxes with spinner arrow
chaneylc Aug 30, 2023
1d8ae11
updated gnss trait to show location updates even if precision quality…
chaneylc Aug 30, 2023
ff10bed
added progress bar to gnss trait when connection drops or location ha…
chaneylc Aug 31, 2023
9ed2390
Merge branch 'main' into v5.5/geonav
trife Sep 1, 2023
5afeec8
strings and changelog
trife Sep 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
Expand Down
134 changes: 113 additions & 21 deletions app/src/main/java/com/fieldbook/tracker/activities/CollectActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
Expand Down Expand Up @@ -44,29 +46,33 @@
import com.fieldbook.tracker.database.DataHelper;
import com.fieldbook.tracker.database.models.ObservationModel;
import com.fieldbook.tracker.database.models.ObservationUnitModel;
import com.fieldbook.tracker.dialogs.GeoNavCollectDialog;
import com.fieldbook.tracker.interfaces.FieldSwitcher;
import com.fieldbook.tracker.location.GPSTracker;
import com.fieldbook.tracker.objects.FieldObject;
import com.fieldbook.tracker.objects.GeoNavHelper;
import com.fieldbook.tracker.objects.InfoBarModel;
import com.fieldbook.tracker.objects.GoProWrapper;
import com.fieldbook.tracker.objects.RangeObject;
import com.fieldbook.tracker.objects.TraitObject;
import com.fieldbook.tracker.objects.VerifyPersonHelper;
import com.fieldbook.tracker.preferences.GeneralKeys;
import com.fieldbook.tracker.traits.BaseTraitLayout;
import com.fieldbook.tracker.traits.CategoricalTraitLayout;
import com.fieldbook.tracker.traits.GNSSTraitLayout;
import com.fieldbook.tracker.traits.GoProTraitLayout;
import com.fieldbook.tracker.traits.LayoutCollections;
import com.fieldbook.tracker.traits.PhotoTraitLayout;
import com.fieldbook.tracker.utilities.CategoryJsonUtil;
import com.fieldbook.tracker.utilities.FieldSwitchImpl;
import com.fieldbook.tracker.utilities.GeoNavHelper;
import com.fieldbook.tracker.utilities.GnssThreadHelper;
import com.fieldbook.tracker.utilities.GoProWrapper;
import com.fieldbook.tracker.utilities.InfoBarHelper;
import com.fieldbook.tracker.utilities.LocationCollectorUtil;
import com.fieldbook.tracker.utilities.SnackbarUtils;
import com.fieldbook.tracker.utilities.SoundHelperImpl;
import com.fieldbook.tracker.utilities.TapTargetUtil;
import com.fieldbook.tracker.utilities.Utils;
import com.fieldbook.tracker.utilities.VerifyPersonHelper;
import com.fieldbook.tracker.utilities.VibrateUtil;
import com.fieldbook.tracker.views.CollectInputView;
import com.fieldbook.tracker.views.RangeBoxView;
import com.fieldbook.tracker.views.TraitBoxView;
Expand Down Expand Up @@ -112,14 +118,18 @@ public class CollectActivity extends ThemedActivity
com.fieldbook.tracker.interfaces.CollectRangeController,
com.fieldbook.tracker.interfaces.CollectTraitController,
InfoBarAdapter.InfoBarController,
GoProTraitLayout.GoProCollector {
GoProTraitLayout.GoProCollector,
GPSTracker.GPSTrackerListener {

public static final int REQUEST_FILE_EXPLORER_CODE = 1;
public static final int BARCODE_COLLECT_CODE = 99;
public static final int BARCODE_SEARCH_CODE = 98;

private GeoNavHelper geoNavHelper;

@Inject
VibrateUtil vibrator;

@Inject
GnssThreadHelper gnssThreadHelper;

Expand All @@ -142,6 +152,8 @@ public class CollectActivity extends ThemedActivity
@Inject
GoProWrapper goProWrapper;

private GPSTracker gps;

public static boolean searchReload;
public static String searchRange;
public static String searchPlot;
Expand Down Expand Up @@ -215,6 +227,12 @@ public class CollectActivity extends ThemedActivity
private AlertDialog dialogMultiMeasureDelete;
private AlertDialog dialogMultiMeasureConfirmDelete;

/**
* GeoNav dialog
*/
private androidx.appcompat.app.AlertDialog dialogGeoNav;
private androidx.appcompat.app.AlertDialog dialogPrecisionLoss;

public void triggerTts(String text) {
if (ep.getBoolean(GeneralKeys.TTS_LANGUAGE_ENABLED, false)) {
ttsHelper.speak(text);
Expand All @@ -224,6 +242,8 @@ public void triggerTts(String text) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

gps = new GPSTracker(this, this, 0, 10000);

guiThread.start();
myGuiHandler = new Handler(guiThread.getLooper()) {
@Override
Expand Down Expand Up @@ -813,6 +833,8 @@ public void onPause() {

geoNavHelper.stopGeoNav();

gnssThreadHelper.stop();

//save the last used trait
if (traitBox.getCurrentTrait() != null)
ep.edit().putString(GeneralKeys.LAST_USED_TRAIT, traitBox.getCurrentTrait().getTrait()).apply();
Expand Down Expand Up @@ -921,10 +943,7 @@ public void onResume() {
//setup logger whenever activity resumes
geoNavHelper.setupGeoNavLogger();

secureBluetooth.withNearby((adapter) -> {
geoNavHelper.startGeoNav();
return null;
});
startGeoNav();
}

verifyPersonHelper.checkLastOpened();
Expand All @@ -942,6 +961,17 @@ public void onResume() {
refreshLock();
}

private void startGeoNav() {
try {
secureBluetooth.withNearby((adapter) -> {
geoNavHelper.startGeoNav();
return null;
});
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* LAST_USED_TRAIT is a preference saved in CollectActivity.onPause
*
Expand Down Expand Up @@ -1250,21 +1280,18 @@ public boolean onOptionsItemSelected(MenuItem item) {

Log.d(GEOTAG, "Menu item clicked.");

geoNavHelper.setMGeoNavActivated(!geoNavHelper.getMGeoNavActivated());
MenuItem navItem = systemMenu.findItem(R.id.action_act_collect_geonav_sw);
if (geoNavHelper.getMGeoNavActivated()) {

navItem.setIcon(R.drawable.ic_explore_black_24dp);

mPrefs.edit().putBoolean(GeneralKeys.GEONAV_AUTO, true).apply();

}
else {
dialogGeoNav = new GeoNavCollectDialog(this).create();

navItem.setIcon(R.drawable.ic_explore_off_black_24dp);
if (!dialogGeoNav.isShowing()) {

mPrefs.edit().putBoolean(GeneralKeys.GEONAV_AUTO, false).apply();
if (getWindow().isActive()) {

try {
dialogGeoNav.show();
} catch (Exception e) {
e.printStackTrace();
}
}
}

return true;
Expand Down Expand Up @@ -1699,7 +1726,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {

String msg = getString(R.string.act_collect_barcode_search_exists_in_other_field, fieldName);

SnackbarUtils.showNavigateSnack(getLayoutInflater(), findViewById(R.id.traitHolder), msg, 8000, null,
SnackbarUtils.showNavigateSnack(getLayoutInflater(), findViewById(R.id.traitHolder), msg, R.id.toolbarBottom,8000, null,
(v) -> switchField(studyId, null));

} else {
Expand Down Expand Up @@ -2094,4 +2121,69 @@ public SecureBluetooth advisor() {
return secureBluetooth;
}

@NonNull
@Override
public VibrateUtil getVibrator() {
return vibrator;
}

@NonNull
@Override
public Context getContext() {
return this;
}

public void showLocationPrecisionLossDialog() {

if (getWindow().isActive()) {

try {

if (dialogPrecisionLoss != null) {
dialogPrecisionLoss.dismiss();
}

dialogPrecisionLoss = new androidx.appcompat.app.AlertDialog.Builder(this)
.setTitle(getString(R.string.dialog_geonav_precision_loss_title))
.setMessage(getString(R.string.dialog_geonav_precision_loss_msg))
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
dialog.dismiss();
})
.show();

} catch (Exception e) {
e.printStackTrace();
}
}
}

@NonNull
@Override
public GPSTracker getGps() {
return gps;
}

@Override
public void onLocationChanged(@NonNull Location location) {

TraitObject trait = getCurrentTrait();

if (trait != null) {

if (trait.getFormat().equals("gnss")) {

((GNSSTraitLayout) traitLayouts.getTraitLayout("gnss"))
.onLocationChanged(location);

}
}
}

@Override
public Location getLocation() {

if (gps == null) return null;

return gps.getLocation(0, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -865,10 +865,10 @@ private void exportPermission() {

@AfterPermissionGranted(PERMISSIONS_REQUEST_TRAIT_DATA)
public void collectDataFilePermission() {
String[] perms = {Manifest.permission.RECORD_AUDIO, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
String[] perms = {Manifest.permission.VIBRATE, Manifest.permission.RECORD_AUDIO, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA};

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
perms = new String[] {Manifest.permission.RECORD_AUDIO, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.CAMERA};
perms = new String[] {Manifest.permission.VIBRATE, Manifest.permission.RECORD_AUDIO, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.CAMERA};
}

if (EasyPermissions.hasPermissions(this, perms)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@
import com.fieldbook.tracker.preferences.GeneralKeys;
import com.fieldbook.tracker.utilities.DocumentTreeUtil;
import com.fieldbook.tracker.utilities.FieldSwitchImpl;
import com.fieldbook.tracker.utilities.SnackbarUtils;
import com.fieldbook.tracker.utilities.TapTargetUtil;
import com.fieldbook.tracker.utilities.Utils;
import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetSequence;
import com.google.android.material.snackbar.Snackbar;

import org.phenoapps.utils.BaseDocumentTreeUtil;

Expand Down Expand Up @@ -178,7 +178,6 @@ public void onCreate(Bundle savedInstanceState) {
fieldList = findViewById(R.id.myList);
mAdapter = new FieldAdapter(thisActivity, database.getAllFieldObjects(), fieldSwitcher);
fieldList.setAdapter(mAdapter);

}

private void showFileDialog() {
Expand Down Expand Up @@ -438,32 +437,39 @@ private void selectPlotByDistance() {

int studyId = model.getStudy_id();

FieldObject study = database.getFieldObject(studyId);

String studyName = study.getExp_name();

if (studyId == ep.getInt(GeneralKeys.SELECTED_FIELD_ID, -1)) {

Snackbar.make(findViewById(R.id.field_editor_parent_linear_layout),
SnackbarUtils.showNavigateSnack(getLayoutInflater(),
findViewById(R.id.main_content),
getString(R.string.activity_field_editor_switch_field_same),
Snackbar.LENGTH_LONG).show();
null,
8000, null, null
);
// Snackbar.make(findViewById(R.id.field_editor_parent_linear_layout),
// Snackbar.LENGTH_LONG).show();

} else {

Snackbar mySnackbar = Snackbar.make(findViewById(R.id.field_editor_parent_linear_layout),
getString(R.string.activity_field_editor_switch_field, String.valueOf(studyId)),
Snackbar.LENGTH_LONG);

mySnackbar.setAction(R.string.activity_field_editor_switch_field_action, (view) -> {

int count = mAdapter.getCount();

for (int i = 0; i < count; i++) {
FieldObject field = mAdapter.getItem(i);
if (field.getExp_id() == studyId) {
mAdapter.getView(i, null, null).performClick();
}
}

});

mySnackbar.show();
SnackbarUtils.showNavigateSnack(
getLayoutInflater(),
findViewById(R.id.main_content),
getString(R.string.activity_field_editor_switch_field, studyName),
null,
8000,
null, (v) -> {
int count = mAdapter.getCount();

for (int i = 0; i < count; i++) {
FieldObject field = mAdapter.getItem(i);
if (field.getExp_id() == studyId) {
mAdapter.getView(i, null, null).performClick();
}
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ public void updateTraitVisibility(String trait, boolean val) {
// String.valueOf(val), trait});
}

public void updateObservationUnit(ObservationUnitModel model, String geoCoordinates) {

open();

ObservationUnitDao.Companion.updateObservationUnit(model, geoCoordinates);

}

public ObservationUnitModel[] getAllObservationUnits() {

open();
Expand Down
Loading
Loading