Commit 9ae5c446 authored by Rahadi Jalu's avatar Rahadi Jalu

Current Changes

parent 2ee4e7a9
# ODK Collect
[![Build status](](
[![Slack status](](
## 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]( and read about example ODK deployments [here](
ODK Collect renders forms that are compliant with the [ODK XForms standard](, a subset of the [XForms 1.1 standard]( with some extensions. The form parsing is done by the [JavaRosa library]( which Collect includes as a jar.
* ODK website: [](
* ODK Collect usage instructions: [](
* ODK community mailing list: [](
* ODK developer mailing list: [](
* ODK developer Slack chat: [](
* ODK developer Slack archive: [](
* ODK developer 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]( or get ([example forms](, [test forms]( an XLSForm.
1. Convert the XLSForm (xlsx) to XForm (xml). Use the [ODK website]( or [XLSForm Offline]( or [pyxform](
1. Once you have the XForm, use [adb]( to push the form to your device (after [enabling USB debugging]( 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]( and add it to your PATH
1. Download and install [Android Studio](
1. Fork the collect project ([why and how to fork](
1. Clone your fork of the project locally. At the command line:
git clone
If you prefer not to use the command line, you can use Android Studio to create a new project from version control using ``.
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]( Enable the Google Drive API [here]( Enable the Google Sheets API [here](
**Google Maps API** - Follow the instructions [here]( 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]( should be a good place to start. There are also currently many issues tagged as [needs reproduction]( 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 in other ways
If you know a language other than English, consider contributing translations through [Transifex](
You can also help by improving this documentation.
## Downloading builds
Per-commit debug builds can be found on [CircleCI]( 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](
## 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](
#### Android Studio Error: `SDK location not found. Define location with sdk.dir in the 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.
......@@ -53,18 +53,6 @@ Secara umum, pengembangan aplikasi lebih lanjut dapat dilakukan dengan langkah-l
7. Untuk melakukan run project, tekan tombol panah hijau di bagian atas dari Android Studio.
> Note: Penggunaan emulator mungkin dapat mengakibatkan aplikasi berjalan lambat. Oleh karena itu, disarankan untuk menggunakan device selama memungkinkan.
## Panduan & Dokumentasi
Berikut adalah *table of content* dari panduan yang tersedia:
1. Instalasi aplikasi
- Menggunakan APK
- Run project pada Android Studio
2. Penggunaan aplikasi
- Konfigurasi Server
- User Interface pemutakhiran
- Keterkaitan Kuesioner
## Credits
Banyak pihak yang telah dilibatkan dalam melakukan pengembangan aplikasi ini. Oleh karena itu, pengembang mengucapkan terima kasih kepada:
......@@ -313,7 +313,7 @@ public class CapiInstanceActivity extends AppCompatActivity
HashMap<String, String> informations = new HashMap<>();
File file = new File(instance.getInstanceFilePath());
InstanceValues values = XmlUtils.getInstanceValues(instance.getInstanceUuid(), file, labels);
InstanceValues values = XmlUtils.getInstanceValues(instance.getInstanceUuid(), file, labels, InstanceValues.STATE_NEUTRAL);
Set<String> parsedXpaths = values.getXPaths();
for(String parsed : parsedXpaths) {
if(parsed.equals(titleSelected)) {
import android.os.Bundle;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
* Author : Rahadi Jalu
* Email :
* Company: Politeknik Statistika STIS
public class GroupActivity extends Activity {
protected void onCreate(@Nullable Bundle 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);
return new TreeMap<>(result);
......@@ -40,26 +40,12 @@ public class HierarchyAdapter extends RecyclerView.Adapter<HierarchyAdapter.View
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
Timber.d("Creating with type %s", viewType);
// BaseHierarchy hierarchy = hierarchies.get(viewType);
// if (hierarchy instanceof PromptHierarchy) {
// ((PromptHierarchy) hierarchy).setOnChangeListener(onChangeListener);
// return new PromptViewHolder(hierarchy.getView());
// } else if (hierarchy instanceof CaptionHierarchy) {
// return new CaptionViewHolder(hierarchy.getView());
// } else {
// // Should not be happening
// return new ViewHolder(hierarchy.getView());
// }
return new ViewHolder(new LinearLayout(parent.getContext()));
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
// if (holder instanceof PromptViewHolder) {
// PromptHierarchy hierarchy = (PromptHierarchy) hierarchies.get(position);
// }
......@@ -60,6 +60,9 @@ public class NodeViewFactory extends BaseNodeViewFactory {
case ModeTreeNode.QUEUED:
case ModeTreeNode.FAILED:
} else {
......@@ -29,7 +29,7 @@ import;
public class InstancePreferenceFragment extends BasePreferenceFragment {
private PreferencesManager manager;
private ListPreference viewModePref, titlePref, constraintPref;
private ListPreference viewModePref, titlePref, constraintPref, filterPref;
private MultiSelectListPreference subtitlePref;
private String formId;
private FormLabels formLabels;
......@@ -53,7 +53,8 @@ public class InstancePreferenceFragment extends BasePreferenceFragment {
List<Form> forms = formsDao.getFormsFromCursor(formsDao.getFormsCursorForFormId(formId));
File file = new File(forms.get(0).getFormFilePath());
List<String> xPaths = XmlUtils.getInstanceXPathList(file);
List<String> xPaths = XmlUtils.getInstanceXPathList(file, false);
formLabels = XmlUtils.getFormLabels(formId, file, xPaths);
entries = new LinkedList<>();
......@@ -87,11 +88,14 @@ public class InstancePreferenceFragment extends BasePreferenceFragment {
if (titlePref != null) {
entries.addFirst("Default Title");
LinkedList<String> titleEntries = new LinkedList<>(entries);
titleEntries.addFirst("Default Title");
LinkedList<String> titleEntryValues = new LinkedList<>(entryValues);
titlePref.setEntries(entries.toArray(new CharSequence[entries.size()]));
titlePref.setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()]));
titlePref.setEntries(titleEntries.toArray(new CharSequence[titleEntries.size()]));
titlePref.setEntryValues(titleEntryValues.toArray(new CharSequence[titleEntryValues.size()]));
String value = (String) manager.getByFormId(PreferencesAPI.KEY_VIEW_MODE, formId);
......@@ -141,6 +145,22 @@ public class InstancePreferenceFragment extends BasePreferenceFragment {
filterPref = (ListPreference) findPreference(PreferencesAPI.KEY_FILTER);
if (filterPref != null) {
LinkedList<String> filterEntries = new LinkedList<>(entries);
LinkedList<String> filterEntryValues = new LinkedList<>(entryValues);
filterPref.setEntries(filterEntries.toArray(new CharSequence[filterEntries.size()]));
filterPref.setEntryValues(filterEntryValues.toArray(new CharSequence[filterEntryValues.size()]));
String val = (String) manager.getByFormId(PreferencesAPI.KEY_FILTER, formId);
setSelectSummary(filterPref, val);
private void setListeners() {
......@@ -228,6 +248,19 @@ public class InstancePreferenceFragment extends BasePreferenceFragment {
if (filterPref != null) {
setSelectSummary(filterPref, (String) manager.getByFormId(PreferencesAPI.KEY_FILTER, formId));
filterPref.setKey(manager.getKey(filterPref.getKey(), formId));
filterPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
setSelectSummary(filterPref, newValue.toString());
return true;
private String getViewModeValue(String entryValue) {
......@@ -253,8 +286,13 @@ public class InstancePreferenceFragment extends BasePreferenceFragment {
private void setSelectSummary(ListPreference preference, String entryValue) {
if(entryValue.isEmpty() || entryValue.trim().length() == 0 || entryValue.equals(PreferencesAPI.TITLE_DEFAULT)) {
if (entryValue == null
|| entryValue.isEmpty()
|| entryValue.trim().length() == 0
|| entryValue.equals(PreferencesAPI.TITLE_DEFAULT)) {
preference.setSummary("Default Title");
} else if (entryValue.equals(PreferencesAPI.FILTER_NONE)) {
} else {
......@@ -263,7 +301,7 @@ public class InstancePreferenceFragment extends BasePreferenceFragment {
private void setMultiSelectSummary(MultiSelectListPreference preference, HashSet<String> set) {
boolean first = true;
if(!set.isEmpty()) {
if (!set.isEmpty()) {
StringBuilder values = new StringBuilder();
for (String v : set) {
if (!first) {
import java.util.HashMap;
* Author : Rahadi Jalu
* Email :
* Company: Politeknik Statistika STIS
public interface InstanceDownloadListener {
void onInstanceDownloadProgressUpdate(int progress, int total, String current);
void onInstanceDownloadCompleted(HashMap<String, String> result);
import java.util.Map;
* Author : Rahadi Jalu
* Email :
* Company: Politeknik Statistika STIS
public interface InstanceListDownloadListener {
void instanceListDownloadingComplete(Map<String, String> instances);
import java.util.List;
* Author : Rahadi Jalu
* Email :
* Company: Politeknik Statistika STIS
public interface InstanceValueListener {
void onValueParsed(List<InstanceValues> values);
......@@ -11,14 +11,23 @@ import java.util.Set;
public class InstanceValues implements Serializable {
// TODO: parsing instance value dobel ning instance karo group activity
public static int STATE_NEUTRAL = 0;
public static int STATE_ACTIVE = 1;
public static int STATE_COMPLETED = 2;
private String instanceId;
private String formId;
private int state;
private Map<String, String> instanceValue;
public InstanceValues(String instanceId, String formId, Map<String, String> instanceValue) {
public InstanceValues(String instanceId, String formId, Map<String, String> instanceValue,
int state) {
this.instanceId = instanceId;
this.formId = formId;
this.instanceValue = instanceValue;
this.state = state;
public InstanceValues putInstanceValue(String xPath, String value) {
......@@ -46,4 +55,7 @@ public class InstanceValues implements Serializable {
return instanceValue.get(xPath);
public int getState() {
return state;
* Author : Rahadi Jalu
* Email :
* 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;
......@@ -11,6 +11,7 @@ public class ModeTreeNode extends TreeNode {
public static final int DOWNLOADED = 0;
public static final int QUEUED = 1;
public static final int FAILED = 2;
private int mode;
private String valueId;
......@@ -9,10 +9,6 @@ import java.util.HashSet;
* Company: Politeknik Statistika STIS
public class PreferencesAPI {
public static final String KEY_CATEGORY_APPEARANCE = "appearance_category";
public static final String KEY_RESPONSE_APPEARANCE = "response_category";
public static final String KEY_CONSTRAINT_APPEARANCE = "constraint_category";
public static final String KEY_VIEW_MODE = "view_mode";
public static final String KEY_TITLE = "title";
......@@ -20,8 +16,12 @@ public class PreferencesAPI {
public static final String KEY_CONSTRAINT = "constraint";
public static final String KEY_FILTER = "filter";
public static final String TITLE_DEFAULT = "default";
public static final String FILTER_NONE = "none";
public static final String VIEW_MODE_ROSTER = "roster";
public static final String VIEW_MODE_CARDS = "cards";
import android.content.SharedPreferences;
import android.database.Cursor;
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.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import timber.log.Timber;
* Author : Rahadi Jalu
* Email :
* Company: Politeknik Statistika STIS
public class InstanceListDownloadTask extends AsyncTask<Void, String, Map<String, String>> {
* Request:
* {
* "filter": {
* "type": "",
* "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 = "";
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;
protected Map<String, String> doInBackground(Void... values) {
SharedPreferences settings =
String downloadListUrl =
String formListUrl = Collect.getInstance().getApplicationContext().getString(
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;
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);
JSONArray filterContents = new JSONArray();
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) {