...
 
Commits (2)
# ODK Collect
![Platform](https://img.shields.io/badge/platform-Android-blue.svg)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Build status](https://circleci.com/gh/opendatakit/collect.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/opendatakit/collect)
[![Slack status](http://slack.opendatakit.org/badge.svg)](http://slack.opendatakit.org)
## Belum Implementasi
Sudah ada pada ODK tetapi belum sempat untuk diimplementasikan
* Merubah pengaturan melalui share QR Code
* Range widget
* Redesign draw activity
* load setting melalui JSON, selain dari collect.settings
ODK Collect is an Android app for filling out forms. It is designed to be used in resource-constrained environments with challenges such as unreliable connectivity or power infrastructure. ODK Collect is part of Open Data Kit (ODK), a free and open-source set of tools which help organizations author, field, and manage mobile data collection solutions. Learn more about the Open Data Kit project and its history [here](https://opendatakit.org/about/) and read about example ODK deployments [here](https://opendatakit.org/about/deployments/).
ODK Collect renders forms that are compliant with the [ODK XForms standard](http://opendatakit.github.io/xforms-spec/), a subset of the [XForms 1.1 standard](https://www.w3.org/TR/xforms/) with some extensions. The form parsing is done by the [JavaRosa library](https://github.com/opendatakit/javarosa) which Collect includes as a jar.
* ODK website: [https://opendatakit.org](https://opendatakit.org)
* ODK Collect usage instructions: [https://opendatakit.org/use/collect](https://opendatakit.org/use/collect/)
* ODK community mailing list: [http://groups.google.com/group/opendatakit](http://groups.google.com/group/opendatakit)
* ODK developer mailing list: [http://groups.google.com/group/opendatakit-developers](http://groups.google.com/group/opendatakit-developers)
* ODK developer Slack chat: [http://slack.opendatakit.org](http://slack.opendatakit.org)
* ODK developer Slack archive: [http://opendatakit.slackarchive.io](http://opendatakit.slackarchive.io)
* ODK developer wiki: [https://github.com/opendatakit/opendatakit/wiki](https://github.com/opendatakit/opendatakit/wiki)
## Release cycle
New versions of ODK Collect are released on the last Sunday of each month. We freeze commits to the master branch on the preceding Wednesday (except for bug fixes).
## Testing a form locally
1. [Make](https://xlsform.org) or get ([example forms](https://github.com/XLSForm/example-forms), [test forms](https://github.com/XLSForm/test-forms)) an XLSForm.
1. Convert the XLSForm (xlsx) to XForm (xml). Use the [ODK website](http://opendatakit.org/xiframe/) or [XLSForm Offline](https://gumroad.com/l/xlsform-offline) or [pyxform](https://github.com/XLSForm/pyxform).
1. Once you have the XForm, use [adb](https://developer.android.com/studio/command-line/adb.html) to push the form to your device (after [enabling USB debugging](https://www.kingoapp.com/root-tutorials/how-to-enable-usb-debugging-mode-on-android.htm)) or emulator.
```
adb push my_form.xml /sdcard/odk/forms/
```
1. Launch ODK Collect and tap `Fill Blank Form`. The new form will be there.
## Setting up your development environment
1. Download and install [Git](https://git-scm.com/downloads) and add it to your PATH
1. Download and install [Android Studio](https://developer.android.com/studio/index.html)
1. Fork the collect project ([why and how to fork](https://help.github.com/articles/fork-a-repo/))
1. Clone your fork of the project locally. At the command line:
git clone https://github.com/YOUR-GITHUB-USERNAME/collect
If you prefer not to use the command line, you can use Android Studio to create a new project from version control using `https://github.com/YOUR-GITHUB-USERNAME/collect`.
1. Open the project in the folder of your clone from Android Studio. To run the project, click on the green arrow at the top of the screen. The emulator is very slow so we generally recommend using a physical device when possible.
## Using APIs for local development
To run functionality that makes API calls from your debug-signed builds, you may need to get an API key or otherwise authorize your app.
**Google Drive and Sheets APIs** - Follow the instructions in the "Generate the signing certificate fingerprint and register your application" section from [here](https://developers.google.com/drive/android/auth). Enable the Google Drive API [here](https://console.developers.google.com/apis/api/drive/). Enable the Google Sheets API [here](https://console.developers.google.com/apis/api/sheets.googleapis.com).
**Google Maps API** - Follow the instructions [here](https://developers.google.com/maps/documentation/android-api/signup). Please be sure not to commit your personal API key to a branch that you will submit a pull request for.
## Contributing code
Any and all contributions to the project are welcome. ODK Collect is used across the world primarily by organizations with a social purpose so you can have real impact!
Issues tagged as [quick win](https://github.com/opendatakit/collect/labels/quick%20win) should be a good place to start. There are also currently many issues tagged as [needs reproduction](https://github.com/opendatakit/collect/labels/needs%20reproduction) which need someone to try to reproduce them with the current version of ODK Collect and comment on the issue with their findings.
If you're ready to contribute code, see [the contribution guide](CONTRIBUTING.md).
## Contributing in other ways
If you know a language other than English, consider contributing translations through [Transifex](https://www.transifex.com/opendatakit/odk-collect/).
You can also help by improving this documentation.
## Downloading builds
Per-commit debug builds can be found on [CircleCI](https://circleci.com/gh/opendatakit/collect). Login with your GitHub account, click the build you'd like, then find the APK in the Artifacts tab.
Current and previous production builds can be found on the [ODK website](https://opendatakit.org/downloads/download-info/odk-collect-apk).
## Troubleshooting
#### Error when running Robolectric tests from Android Studio on macOS: `build/intermediates/bundles/debug/AndroidManifest.xml (No such file or directory)`
> Configure the default JUnit test runner configuration in order to work around a bug where IntelliJ / Android Studio does not set the working directory to the module being tested. This can be accomplished by editing the run configurations, Defaults -> JUnit and changing the working directory value to $MODULE_DIR$.
> Source: [Robolectric Wiki](https://github.com/robolectric/robolectric/wiki/Running-tests-in-Android-Studio#notes-for-mac).
#### Android Studio Error: `SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.`
When cloning the project from Android Studio, click "No" when prompted to open the `build.gradle` file and then open project.
package id.ac.stis.capi.lessthink.activities;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import id.ac.stis.capi.lessthink.models.InstanceValues;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class GroupActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
private Map<String, List<InstanceValues>> getUniqueInstanceValuesByGroup(List<InstanceValues> instanceValues, String groupBy) {
Map<String, List<InstanceValues>> result = new HashMap<>();
for (InstanceValues values : instanceValues) {
String groupValue = values.getInstanceValue(groupBy);
if (groupValue == null) {
return null;
}
if(groupValue.isEmpty() || groupBy.trim().length() == 0) {
groupValue = "<Other>";
}
List<InstanceValues> group = result.get(groupValue);
if (group == null) {
group = new ArrayList<>();
result.put(groupValue, group);
}
group.add(values);
}
return new TreeMap<>(result);
}
}
package id.ac.stis.capi.lessthink.listeners;
import java.util.HashMap;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public interface InstanceDownloadListener {
void onInstanceDownloadProgressUpdate(int progress, int total, String current);
void onInstanceDownloadCompleted(HashMap<String, String> result);
}
package id.ac.stis.capi.lessthink.listeners;
import java.util.Map;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public interface InstanceListDownloadListener {
void instanceListDownloadingComplete(Map<String, String> instances);
}
package id.ac.stis.capi.lessthink.listeners;
import java.util.List;
import id.ac.stis.capi.lessthink.models.InstanceValues;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public interface InstanceValueListener {
void onValueParsed(List<InstanceValues> values);
}
package id.ac.stis.capi.lessthink.models;
import java.io.Serializable;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class MediaFileModel implements Serializable {
public String fileName;
public String hash;
public String downloadUrl;
public MediaFileModel(String fileName, String hash, String downloadUrl) {
this.fileName = fileName;
this.hash = hash;
this.downloadUrl = downloadUrl;
}
public String getFileName() {
return fileName;
}
public String getHash() {
return hash;
}
public String getDownloadUrl() {
return downloadUrl;
}
}
package id.ac.stis.capi.lessthink.tasks;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.opendatakit.httpclientandroidlib.HttpEntity;
import org.opendatakit.httpclientandroidlib.HttpResponse;
import org.opendatakit.httpclientandroidlib.NameValuePair;
import org.opendatakit.httpclientandroidlib.client.HttpClient;
import org.opendatakit.httpclientandroidlib.client.entity.UrlEncodedFormEntity;
import org.opendatakit.httpclientandroidlib.client.methods.HttpPost;
import org.opendatakit.httpclientandroidlib.message.BasicNameValuePair;
import org.opendatakit.httpclientandroidlib.protocol.HttpContext;
import org.opendatakit.httpclientandroidlib.util.EntityUtils;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import id.ac.stis.capi.R;
import id.ac.stis.capi.lessthink.listeners.InstanceListDownloadListener;
import id.ac.stis.capi.lessthink.preferences.PreferencesAPI;
import id.ac.stis.capi.lessthink.preferences.PreferencesManager;
import id.ac.stis.capi.lessthink.utils.XmlUtils;
import id.ac.stis.capi.odk.application.Collect;
import id.ac.stis.capi.odk.dao.FormsDao;
import id.ac.stis.capi.odk.dao.InstancesDao;
import id.ac.stis.capi.odk.dto.Form;
import id.ac.stis.capi.odk.dto.Instance;
import id.ac.stis.capi.odk.preferences.GeneralSharedPreferences;
import id.ac.stis.capi.odk.preferences.PreferenceKeys;
import id.ac.stis.capi.odk.provider.InstanceProviderAPI;
import id.ac.stis.capi.odk.utilities.WebUtils;
import timber.log.Timber;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class InstanceListDownloadTask extends AsyncTask<Void, String, Map<String, String>> {
/**
* Request:
* {
* "filter": {
* "type": "http://www.opendatakit.org/filter",
* "filtercontent": [{
* "attributeDecode": "vsen_p/vsen_p_ruta:id_pml",
* "attributeValue": "rpml",
* "attributeOperation": "EQUAL"
* }]
* }
* }
*/
// Sementara belum support cursor
private static final String KEY_FORM_ID = "formId";
private static final String KEY_FILTER = "filter";
private static final String KEY_DATA = "data";
private static final String KEY_TYPE = "type";
private static final String KEY_META_INSTANCE_ID = "*meta-instance-id*";
private static final String KEY_INSTANCE_ID = "instanceID";
private static final String KEY_INSTANCE_NAME = "instanceName";
private static final String KEY_FILTER_CONTENT = "filtercontent";
private static final String KEY_ATTRIBUTE_DECODE = "attributeDecode";
private static final String KEY_ATTRIBUTE_VALUE = "attributeValue";
private static final String KEY_ATTRIBUTE_OPERATION = "attributeOperation";
private static final String TYPE_FILTER = "http://www.opendatakit.org/filter";
private static final String ATTRIBUTE_OPERATION_EQUAL = "EQUAL";
private final String formId;
private InstanceListDownloadListener stateListener;
private Map<String, String> downloadedUri;
public InstanceListDownloadTask(String formId) {
this.formId = formId;
}
@Override
protected Map<String, String> doInBackground(Void... values) {
SharedPreferences settings =
PreferenceManager.getDefaultSharedPreferences(
Collect.getInstance().getBaseContext());
String downloadListUrl =
settings.getString(PreferenceKeys.KEY_SERVER_URL,
Collect.getInstance().getString(R.string.default_server_url));
String formListUrl = Collect.getInstance().getApplicationContext().getString(
R.string.odk_capi_submission_filter);
String downloadPath = settings.getString(PreferenceKeys.KEY_FILTER_URL, formListUrl);
downloadListUrl += downloadPath;
Collect.getInstance().getActivityLogger().logAction(this, formListUrl, downloadListUrl);
// get shared HttpContext so that authentication and cookies are retained.
HttpContext localContext = Collect.getInstance().getHttpContext();
HttpClient httpclient = WebUtils.createHttpClient(WebUtils.CONNECTION_TIMEOUT);
Map<String, String> instances = new HashMap<>();
try {
PreferencesManager preferencesManager = PreferencesManager.getInstance();
String filterXPath = (String) preferencesManager.getByFormId(PreferencesAPI.KEY_FILTER, formId);
String formattedXPath = null;
if (filterXPath == null) {
FormsDao formsDao = new FormsDao();
List<Form> forms = formsDao.getFormsFromCursor(formsDao.getFormsCursorForFormId(formId));
File file = new File(forms.get(0).getFormFilePath());
List<String> xPaths = XmlUtils.getInstanceXPathList(file, true);
String chosenXPath = null;
for (String xPath : xPaths) {
if (xPath.endsWith("id_pcl")) {
chosenXPath = xPath;
break;
}
}
if (chosenXPath != null) {
formattedXPath = getFormattedXPath(chosenXPath);
}
} else if (!filterXPath.equals(PreferencesAPI.FILTER_NONE)) {
formattedXPath = getFormattedXPath(filterXPath);
}
List<NameValuePair> nameValuePairs = new ArrayList<>();
nameValuePairs.add(new BasicNameValuePair(KEY_FORM_ID, formId));
if (formattedXPath != null) {
GeneralSharedPreferences pref = GeneralSharedPreferences.getInstance();
String username = (String) pref.get(PreferenceKeys.KEY_USERNAME);
JSONObject filterContent = new JSONObject();
filterContent.put(KEY_ATTRIBUTE_DECODE, formattedXPath);
filterContent.put(KEY_ATTRIBUTE_VALUE, username);
filterContent.put(KEY_ATTRIBUTE_OPERATION, ATTRIBUTE_OPERATION_EQUAL);
JSONArray filterContents = new JSONArray();
filterContents.put(filterContent);
JSONObject filter = new JSONObject();
filter.put(KEY_TYPE, TYPE_FILTER);
filter.put(KEY_FILTER_CONTENT, filterContents);
JSONObject request = new JSONObject();
request.put(KEY_FILTER, filter);
nameValuePairs.add(new BasicNameValuePair(KEY_FILTER, request.toString()));
}
HttpPost httpPost = WebUtils.createOpenRosaHttpPost(Uri.parse(downloadListUrl));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, Charset.forName("UTF-8")));
HttpResponse response = httpclient.execute(httpPost, localContext);
HttpEntity httpEntity = response.getEntity();
String jsonString = EntityUtils.toString(httpEntity);
// Timber.d("Response: %s", jsonString);
JSONObject jsonObject = new JSONObject(jsonString);
JSONArray uriList = jsonObject.getJSONArray(KEY_DATA);
for (int i = 0; i < uriList.length(); i++) {
JSONObject data = uriList.getJSONObject(i);
String metaInstanceId = data.getString(KEY_META_INSTANCE_ID);
String instanceId = data.getString(KEY_INSTANCE_ID);
String instanceName = data.getString(KEY_INSTANCE_NAME);
if (!isInstanceExists(instanceId)) {
instances.put(metaInstanceId, instanceName);
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
this.downloadedUri = instances;
return instances;
}
private String getFormattedXPath(String unformattedXPath) {
// initial value, crop first '/' (/foo/bar => foo/bar)
String result = unformattedXPath.substring(1);
// replace '/' with ':' (foo/bar => foo:bar)
result = result.replace("/", ":");
// add form Id (foo:bar => formId/foo:bar)
result = formId + "/" + result;
return result;
}
private boolean isInstanceExists(String uri) {
InstancesDao instancesDao = new InstancesDao();
String selection = InstanceProviderAPI.InstanceColumns.INSTANCE_UUID + "=?";
String[] selectionArgs = new String[]{uri};
Cursor c = instancesDao.getInstancesCursor(selection, selectionArgs);
List<Instance> instances = instancesDao.getInstancesFromCursor(c);
return instances != null && instances.size() > 0;
}
@Override
protected void onPostExecute(Map<String, String> value) {
synchronized (this) {
if (stateListener != null) {
stateListener.instanceListDownloadingComplete(value);
}
}
}
public void setDownloaderListener(InstanceListDownloadListener sl) {
synchronized (this) {
stateListener = sl;
}
}
public Map<String, String> getDownloadedUri() {
return downloadedUri;
}
}
\ No newline at end of file
package id.ac.stis.capi.lessthink.tasks;
import android.database.Cursor;
import android.os.AsyncTask;
import java.io.File;
import java.util.LinkedList;
import java.util.List;
import id.ac.stis.capi.lessthink.listeners.InstanceValueListener;
import id.ac.stis.capi.lessthink.models.FormLabels;
import id.ac.stis.capi.lessthink.models.InstanceValues;
import id.ac.stis.capi.lessthink.utils.XmlUtils;
import id.ac.stis.capi.odk.dao.InstancesDao;
import id.ac.stis.capi.odk.dto.Instance;
import id.ac.stis.capi.odk.provider.InstanceProviderAPI;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class InstanceValueTask extends AsyncTask<Void, Void, List<InstanceValues>> {
private FormLabels formLabels;
private InstanceValueListener instanceValueListener;
public InstanceValueTask(FormLabels formLabels) {
this.formLabels = formLabels;
}
public void setInstanceValueListener(
InstanceValueListener instanceValueListener) {
this.instanceValueListener = instanceValueListener;
}
@Override
protected List<InstanceValues> doInBackground(Void... voids) {
List<InstanceValues> instanceValues = new LinkedList<>();
String selection = InstanceProviderAPI.InstanceColumns.LATEST + " =? AND " +
InstanceProviderAPI.InstanceColumns.JR_FORM_ID + " =?";
String[] selectionArgs =
new String[]{InstanceProviderAPI.LATEST_VERSION, formLabels.getFormId()};
InstancesDao instancesDao = new InstancesDao();
// TODO: 30/06/2018 Sorting order
Cursor data = instancesDao.getInstancesCursor(null, selection, selectionArgs, null);
List<Instance> instanceList = instancesDao.getInstancesFromCursor(data);
for (Instance instance : instanceList) {
File f = new File(instance.getInstanceFilePath());
int state = InstanceValues.STATE_NEUTRAL;
switch (instance.getStatus().trim()) {
case InstanceProviderAPI.STATUS_COMPLETE:
case InstanceProviderAPI.STATUS_INCOMPLETE:
case InstanceProviderAPI.STATUS_SUBMISSION_FAILED:
case InstanceProviderAPI.STATUS_SUBMITTED:
}
InstanceValues values =
XmlUtils.getInstanceValues(instance.getInstanceUuid(), f, formLabels, state);
instanceValues.add(values);
}
return instanceValues;
}
@Override
protected void onPostExecute(List<InstanceValues> instanceValues) {
super.onPostExecute(instanceValues);
if (instanceValueListener != null) {
instanceValueListener.onValueParsed(instanceValues);
}
}
}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM17,15.59L15.59,17 12,13.41 8.41,17 7,15.59 10.59,12 7,8.41 8.41,7 12,10.59 15.59,7 17,8.41 13.41,12 17,15.59z"/>
</vector>
#Wed Jun 20 16:02:20 ICT 2018
gradle.version=4.1