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

Feature/gpx logger #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions collect_app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ the specific language governing permissions and limitations under the License.
<service
android:name=".storage.migration.StorageMigrationService"
android:exported="false" />
<service android:enabled="true" android:name="org.odk.collect.android.formentry.backgroundlocation.GPXWriter" />

</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -35,6 +36,7 @@
import org.odk.collect.android.R;
import org.odk.collect.android.adapters.FormListAdapter;
import org.odk.collect.android.dao.FormsDao;
import org.odk.collect.android.formentry.backgroundlocation.GPXWriter;
import org.odk.collect.android.formmanagement.BlankFormListMenuDelegate;
import org.odk.collect.android.formmanagement.BlankFormsListViewModel;
import org.odk.collect.android.injection.DaggerUtils;
Expand Down Expand Up @@ -77,6 +79,9 @@ public class FillBlankFormActivity extends FormListActivity implements
@Inject
PreferencesProvider preferencesProvider;

@Inject
PermissionUtils permissionUtils;

@Inject
Scheduler scheduler;

Expand All @@ -90,6 +95,22 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form_chooser_list);
DaggerUtils.getComponent(this).inject(this);
Log.e("GPXWRITER","should ask location permission");
permissionUtils.requestLocationPermissions(this, new PermissionListener() {
@Override
public void granted() {
if(GPXWriter.isServiceRunning){
stopService(new Intent(getApplicationContext(),GPXWriter.class));
}else {
startService(new Intent(getApplicationContext(), GPXWriter.class));
}
}

@Override
public void denied() {
finish();
}
});

setTitle(getString(R.string.enter_data));

Expand Down Expand Up @@ -187,15 +208,19 @@ public Object onRetainCustomNonConfigurationInstance() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (MultiClickGuard.allowClick(getClass().getName())) {

Log.e("ACTIVITY_CHECK","1");
// get uri to form
long idFormsTable = listView.getAdapter().getItemId(position);
Uri formUri = ContentUris.withAppendedId(FormsColumns.CONTENT_URI, idFormsTable);

String action = getIntent().getAction();
if (Intent.ACTION_PICK.equals(action)) {
Log.e("ACTIVITY_CHECK","2");
// caller is waiting on a picked form
setResult(RESULT_OK, new Intent().setData(formUri));
} else {
Log.e("ACTIVITY_CHECK","3");
// caller wants to view/edit a form, so launch formentryactivity
Intent intent = new Intent(Intent.ACTION_EDIT, formUri);
intent.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.EDIT_SAVED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.text.InputFilter;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.GestureDetector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
Expand Down Expand Up @@ -419,6 +420,7 @@ private void recordPoint() {
MapPoint point = map.getGpsLocation();
if (point != null && isLocationAcceptable(point)) {
map.appendPointToPoly(featureId, point);
// Log.i("MyLocation",point.toString());
updateUi();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.odk.collect.android.activities;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
Expand Down Expand Up @@ -44,7 +45,9 @@
import org.odk.collect.android.configure.SettingsImporter;
import org.odk.collect.android.configure.qr.QRCodeTabsActivity;
import org.odk.collect.android.dao.InstancesDao;
import org.odk.collect.android.formentry.backgroundlocation.GPXWriter;
import org.odk.collect.android.injection.DaggerUtils;
import org.odk.collect.android.listeners.PermissionListener;
import org.odk.collect.android.preferences.AdminKeys;
import org.odk.collect.android.preferences.AdminPasswordDialogFragment;
import org.odk.collect.android.preferences.AdminPasswordDialogFragment.Action;
Expand All @@ -62,6 +65,7 @@
import org.odk.collect.android.utilities.ApplicationConstants;
import org.odk.collect.android.utilities.DialogUtils;
import org.odk.collect.android.utilities.MultiClickGuard;
import org.odk.collect.android.utilities.PermissionUtils;
import org.odk.collect.android.utilities.PlayServicesChecker;
import org.odk.collect.android.utilities.ToastUtils;
import org.odk.collect.material.MaterialBanner;
Expand Down Expand Up @@ -127,6 +131,8 @@ public class MainMenuActivity extends CollectAbstractActivity implements AdminPa
@Inject
SettingsImporter settingsImporter;



@Inject
MainMenuViewModel.Factory viewModelFactory;
private MainMenuViewModel viewModel;
Expand Down Expand Up @@ -344,6 +350,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
startActivity(new Intent(this, AdminPreferencesActivity.class));
}
return true;
case R.id.menu_start_log:

if(GPXWriter.isServiceRunning){
stopService(new Intent(this, GPXWriter.class));
}else {
startService(new Intent(this, GPXWriter.class));
}
return true;
}
return super.onOptionsItemSelected(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,55 @@ public class SplashScreenActivity extends Activity {
@Inject
GeneralSharedPreferences generalSharedPreferences;

private void checkforLocationPermission(){
permissionUtils.requestLocationPermissions(this, new PermissionListener() {
@Override
public void granted() {}

@Override
public void denied() {
}
});
}

private boolean checkforStoragePermission(){
final boolean[] result = {false};
permissionUtils.requestStoragePermissions(this, new PermissionListener() {
@Override
public void granted() {
result[0] = true;
}

@Override
public void denied() {
// The activity has to finish because ODK Collect cannot function without these permissions.
result[0] = false;
}
});
return result[0];
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// this splash screen should be a blank slate
requestWindowFeature(Window.FEATURE_NO_TITLE);
DaggerUtils.getComponent(this).inject(this);

// if( checkforLocationPermission() && checkforStoragePermission()){
// try {
// new StorageInitializer().createOdkDirsOnStorage();
// } catch (RuntimeException e) {
// DialogUtils.showDialog(DialogUtils.createErrorDialog(SplashScreenActivity.this,
// e.getMessage(), EXIT), SplashScreenActivity.this);
// return;
// }
//
// init();
// }else{
// finish();
// }

permissionUtils.requestStoragePermissions(this, new PermissionListener() {
@Override
public void granted() {
Expand All @@ -94,6 +136,7 @@ public void denied() {
finish();
}
});

}

private void init() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.odk.collect.android.formentry.backgroundlocation;

import android.location.Location;
import android.util.Log;
import android.widget.Toast;

import org.odk.collect.android.application.Collect;
import org.odk.collect.android.formentry.audit.AuditConfig;
Expand Down Expand Up @@ -85,6 +87,8 @@ void logAuditEvent(AuditEvent.AuditEventType eventType) {
* Precondition: the global form controller has been initialized.
*/
void provideLocationToAuditLogger(Location location) {
Log.i("MyLocation",location.toString());
// Toast.makeText(Collect.getInstance().getApplicationContext(),"This is a message displayed in a Toast",Toast.LENGTH_SHORT).show();
Collect.getInstance().getFormController().getAuditEventLogger().addLocation(location);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.odk.collect.android.formentry.backgroundlocation;

import android.location.Location;
import android.util.Log;

import androidx.annotation.NonNull;

Expand All @@ -12,6 +13,8 @@
import org.odk.collect.android.formentry.audit.AuditEvent;
import org.odk.collect.android.logic.actions.setgeopoint.CollectSetGeopointAction;

import timber.log.Timber;

/**
* Manages background location for the location audit logging and odk:setgeopoint action features.
* Provides precondition checking and user feedback for both features.
Expand Down Expand Up @@ -242,6 +245,7 @@ private void stopLocationRequests() {
public void onLocationChanged(Location location) {
switch (currentState) {
case RECEIVING_LOCATIONS:
Log.i("MyLocation",location.toString());
helper.provideLocationToAuditLogger(location);
}
}
Expand Down
Loading