Search in sources :

Example 1 with PropertyManager

use of org.odk.collect.android.logic.PropertyManager in project collect by opendatakit.

the class FormMetadataFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.form_metadata_preferences);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    PropertyManager pm = new PropertyManager(getActivity());
    initPrefFromProp(pm, prefs, PROPMGR_USERNAME, KEY_METADATA_USERNAME);
    initPrefFromProp(pm, prefs, PROPMGR_PHONE_NUMBER, KEY_METADATA_PHONENUMBER);
    initPrefFromProp(pm, prefs, PROPMGR_EMAIL, KEY_METADATA_EMAIL);
    initPrefFromProp(pm, prefs, PROPMGR_DEVICE_ID, null);
    initPrefFromProp(pm, prefs, PROPMGR_SUBSCRIBER_ID, null);
    initPrefFromProp(pm, prefs, PROPMGR_SIM_SERIAL, null);
}
Also used : SharedPreferences(android.content.SharedPreferences) PropertyManager(org.odk.collect.android.logic.PropertyManager)

Example 2 with PropertyManager

use of org.odk.collect.android.logic.PropertyManager in project collect by opendatakit.

the class Collect method initProperties.

public void initProperties() {
    PropertyManager mgr = new PropertyManager(this);
    // Use the server username by default if the metadata username is not defined
    if ((mgr.getSingularProperty(PROPMGR_USERNAME) == null || mgr.getSingularProperty(PROPMGR_USERNAME).isEmpty())) {
        mgr.putProperty(PROPMGR_USERNAME, SCHEME_USERNAME, (String) GeneralSharedPreferences.getInstance().get(KEY_USERNAME));
    }
    FormController.initializeJavaRosa(mgr);
    activityLogger = new ActivityLogger(mgr.getSingularProperty(PropertyManager.PROPMGR_DEVICE_ID));
}
Also used : ActivityLogger(org.odk.collect.android.database.ActivityLogger) PropertyManager(org.odk.collect.android.logic.PropertyManager)

Example 3 with PropertyManager

use of org.odk.collect.android.logic.PropertyManager in project collect by opendatakit.

the class InstanceServerUploader method processChunk.

private boolean processChunk(int low, int high, Outcome outcome, Long... values) {
    if (values == null) {
        // don't try anything if values is null
        return false;
    }
    StringBuilder selectionBuf = new StringBuilder(InstanceColumns._ID + " IN (");
    String[] selectionArgs = new String[high - low];
    for (int i = 0; i < (high - low); i++) {
        if (i > 0) {
            selectionBuf.append(",");
        }
        selectionBuf.append("?");
        selectionArgs[i] = values[i + low].toString();
    }
    selectionBuf.append(")");
    String selection = selectionBuf.toString();
    String deviceId = new PropertyManager(Collect.getInstance().getApplicationContext()).getSingularProperty(PropertyManager.withUri(PropertyManager.PROPMGR_DEVICE_ID));
    // get shared HttpContext so that authentication and cookies are retained.
    HttpContext localContext = Collect.getInstance().getHttpContext();
    Map<Uri, Uri> uriRemap = new HashMap<Uri, Uri>();
    Cursor c = null;
    try {
        c = new InstancesDao().getInstancesCursor(selection, selectionArgs);
        if (c != null && c.getCount() > 0) {
            c.moveToPosition(-1);
            while (c.moveToNext()) {
                if (isCancelled()) {
                    return false;
                }
                publishProgress(c.getPosition() + 1 + low, values.length);
                String instance = c.getString(c.getColumnIndex(InstanceColumns.INSTANCE_FILE_PATH));
                String id = c.getString(c.getColumnIndex(InstanceColumns._ID));
                Uri toUpdate = Uri.withAppendedPath(InstanceColumns.CONTENT_URI, id);
                // Use the app's configured URL unless the form included a submission URL
                int subIdx = c.getColumnIndex(InstanceColumns.SUBMISSION_URI);
                String urlString = c.isNull(subIdx) ? getServerSubmissionURL() : c.getString(subIdx).trim();
                // add the deviceID to the request...
                try {
                    urlString += "?deviceID=" + URLEncoder.encode(deviceId, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    // unreachable...
                    Timber.i(e, "Error encoding URL for device id : %s", deviceId);
                }
                if (!uploadOneSubmission(urlString, id, instance, toUpdate, localContext, uriRemap, outcome)) {
                    // get credentials...
                    return false;
                }
            }
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return true;
}
Also used : InstancesDao(org.odk.collect.android.dao.InstancesDao) HashMap(java.util.HashMap) PropertyManager(org.odk.collect.android.logic.PropertyManager) HttpContext(org.opendatakit.httpclientandroidlib.protocol.HttpContext) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Cursor(android.database.Cursor) Uri(android.net.Uri)

Aggregations

PropertyManager (org.odk.collect.android.logic.PropertyManager)3 SharedPreferences (android.content.SharedPreferences)1 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 InstancesDao (org.odk.collect.android.dao.InstancesDao)1 ActivityLogger (org.odk.collect.android.database.ActivityLogger)1 HttpContext (org.opendatakit.httpclientandroidlib.protocol.HttpContext)1