List of usage examples for android.content ContentValues ContentValues
public ContentValues()
From source file:org.opendatakit.survey.android.tasks.InstanceUploaderTask.java
/** * Uploads to urlString the submission identified by id with filepath of * instance//w ww . ja v a 2s . com * * @param urlString * destination URL * @param id * -- _ID in the InstanceColumns table. * @param instanceFilePath * @param httpclient * - client connection * @param localContext * - context (e.g., credentials, cookies) for client connection * @param uriRemap * - mapping of Uris to avoid redirects on subsequent invocations * @return false if credentials are required and we should terminate * immediately. */ private boolean uploadOneSubmission(String urlString, Uri toUpdate, String id, String submissionInstanceId, FileSet instanceFiles, HttpClient httpclient, HttpContext localContext, Map<URI, URI> uriRemap) { ContentValues cv = new ContentValues(); cv.put(InstanceColumns.SUBMISSION_INSTANCE_ID, submissionInstanceId); URI u = null; try { URL url = new URL(URLDecoder.decode(urlString, CharEncoding.UTF_8)); u = url.toURI(); } catch (MalformedURLException e) { WebLogger.getLogger(appName).printStackTrace(e); mOutcome.mResults.put(id, fail + "invalid url: " + urlString + " :: details: " + e.getMessage()); cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMISSION_FAILED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; } catch (URISyntaxException e) { WebLogger.getLogger(appName).printStackTrace(e); mOutcome.mResults.put(id, fail + "invalid uri: " + urlString + " :: details: " + e.getMessage()); cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMISSION_FAILED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; } catch (UnsupportedEncodingException e) { WebLogger.getLogger(appName).printStackTrace(e); mOutcome.mResults.put(id, fail + "invalid url: " + urlString + " :: details: " + e.getMessage()); cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMISSION_FAILED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; } // NOTE: ODK Survey assumes you are interfacing with an // OpenRosa-compliant server if (uriRemap.containsKey(u)) { // we already issued a head request and got a response, // so we know the proper URL to send the submission to // and the proper scheme. We also know that it was an // OpenRosa compliant server. u = uriRemap.get(u); } else { // we need to issue a head request HttpHead httpHead = WebUtils.get().createOpenRosaHttpHead(u); // prepare response HttpResponse response = null; try { response = httpclient.execute(httpHead, localContext); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 401) { WebUtils.get().discardEntityBytes(response); // we need authentication, so stop and return what we've // done so far. mOutcome.mAuthRequestingServer = u; return false; } else if (statusCode == 204) { Header[] locations = response.getHeaders("Location"); WebUtils.get().discardEntityBytes(response); if (locations != null && locations.length == 1) { try { URL url = new URL(URLDecoder.decode(locations[0].getValue(), CharEncoding.UTF_8)); URI uNew = url.toURI(); if (u.getHost().equalsIgnoreCase(uNew.getHost())) { // trust the server to tell us a new location // ... and possibly to use https instead. uriRemap.put(u, uNew); u = uNew; } else { // Don't follow a redirection attempt to a // different host. // We can't tell if this is a spoof or not. mOutcome.mResults.put(id, fail + "Unexpected redirection attempt to a different host: " + uNew.toString()); cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMISSION_FAILED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; } } catch (Exception e) { WebLogger.getLogger(appName).printStackTrace(e); mOutcome.mResults.put(id, fail + urlString + " " + e.getMessage()); cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMISSION_FAILED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; } } } else { // may be a server that does not handle WebUtils.get().discardEntityBytes(response); WebLogger.getLogger(appName).w(t, "Status code on Head request: " + statusCode); if (statusCode >= 200 && statusCode <= 299) { mOutcome.mResults.put(id, fail + "Invalid status code on Head request. If you have a web proxy, you may need to login to your network. "); cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMISSION_FAILED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; } } } catch (ClientProtocolException e) { WebLogger.getLogger(appName).printStackTrace(e); WebLogger.getLogger(appName).e(t, e.getMessage()); ClientConnectionManagerFactory.get(appName).clearHttpConnectionManager(); mOutcome.mResults.put(id, fail + "Client Protocol Exception"); cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMISSION_FAILED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; } catch (ConnectTimeoutException e) { WebLogger.getLogger(appName).printStackTrace(e); WebLogger.getLogger(appName).e(t, e.getMessage()); ClientConnectionManagerFactory.get(appName).clearHttpConnectionManager(); mOutcome.mResults.put(id, fail + "Connection Timeout"); cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMISSION_FAILED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; } catch (UnknownHostException e) { WebLogger.getLogger(appName).printStackTrace(e); ClientConnectionManagerFactory.get(appName).clearHttpConnectionManager(); mOutcome.mResults.put(id, fail + e.getMessage() + " :: Network Connection Failed"); WebLogger.getLogger(appName).e(t, e.getMessage()); cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMISSION_FAILED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; } catch (SocketTimeoutException e) { WebLogger.getLogger(appName).printStackTrace(e); WebLogger.getLogger(appName).e(t, e.getMessage()); ClientConnectionManagerFactory.get(appName).clearHttpConnectionManager(); mOutcome.mResults.put(id, fail + "Connection Timeout"); cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMISSION_FAILED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; } catch (HttpHostConnectException e) { WebLogger.getLogger(appName).printStackTrace(e); WebLogger.getLogger(appName).e(t, e.toString()); ClientConnectionManagerFactory.get(appName).clearHttpConnectionManager(); mOutcome.mResults.put(id, fail + "Network Connection Refused"); cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMISSION_FAILED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; } catch (Exception e) { WebLogger.getLogger(appName).printStackTrace(e); ClientConnectionManagerFactory.get(appName).clearHttpConnectionManager(); mOutcome.mResults.put(id, fail + "Generic Exception"); WebLogger.getLogger(appName).e(t, e.getMessage()); cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMISSION_FAILED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; } } // At this point, we may have updated the uri to use https. // This occurs only if the Location header keeps the host name // the same. If it specifies a different host name, we error // out. // // And we may have set authentication cookies in our // cookiestore (referenced by localContext) that will enable // authenticated publication to the server. // // get instance file File instanceFile = instanceFiles.instanceFile; if (!instanceFile.exists()) { mOutcome.mResults.put(id, fail + "instance XML file does not exist!"); cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMISSION_FAILED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; } List<MimeFile> files = instanceFiles.attachmentFiles; boolean first = true; int j = 0; int lastJ; while (j < files.size() || first) { lastJ = j; first = false; HttpPost httppost = WebUtils.get().createOpenRosaHttpPost(u, mAuth); long byteCount = 0L; // mime post MultipartEntity entity = new MultipartEntity(); // add the submission file first... FileBody fb = new FileBody(instanceFile, "text/xml"); entity.addPart("xml_submission_file", fb); WebLogger.getLogger(appName).i(t, "added xml_submission_file: " + instanceFile.getName()); byteCount += instanceFile.length(); for (; j < files.size(); j++) { MimeFile mf = files.get(j); File f = mf.file; String contentType = mf.contentType; fb = new FileBody(f, contentType); entity.addPart(f.getName(), fb); byteCount += f.length(); WebLogger.getLogger(appName).i(t, "added " + contentType + " file " + f.getName()); // we've added at least one attachment to the request... if (j + 1 < files.size()) { long nextFileLength = (files.get(j + 1).file.length()); if ((j - lastJ + 1 > 100) || (byteCount + nextFileLength > 10000000L)) { // the next file would exceed the 10MB threshold... WebLogger.getLogger(appName).i(t, "Extremely long post is being split into multiple posts"); try { StringBody sb = new StringBody("yes", Charset.forName(CharEncoding.UTF_8)); entity.addPart("*isIncomplete*", sb); } catch (Exception e) { WebLogger.getLogger(appName).printStackTrace(e); // never happens... } ++j; // advance over the last attachment added... break; } } } httppost.setEntity(entity); // prepare response and return uploaded HttpResponse response = null; try { response = httpclient.execute(httppost, localContext); int responseCode = response.getStatusLine().getStatusCode(); WebUtils.get().discardEntityBytes(response); WebLogger.getLogger(appName).i(t, "Response code:" + responseCode); // verify that the response was a 201 or 202. // If it wasn't, the submission has failed. if (responseCode != 201 && responseCode != 202) { if (responseCode == 200) { mOutcome.mResults.put(id, fail + "Network login failure? Again?"); } else { mOutcome.mResults.put(id, fail + response.getStatusLine().getReasonPhrase() + " (" + responseCode + ") at " + urlString); } cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMISSION_FAILED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; } } catch (Exception e) { WebLogger.getLogger(appName).printStackTrace(e); mOutcome.mResults.put(id, fail + "Generic Exception. " + e.getMessage()); cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMISSION_FAILED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; } } // if it got here, it must have worked mOutcome.mResults.put(id, appContext.getString(R.string.success)); cv.put(InstanceColumns.XML_PUBLISH_STATUS, InstanceColumns.STATUS_SUBMITTED); appContext.getContentResolver().update(toUpdate, cv, null, null); return true; }
From source file:grytsenko.coworkers.web.Employee.java
/** * Obtains data about email address for {@link ContentResolver}. * //from ww w .j a v a 2 s . c om * @return the set of values. */ public ContentValues getEmail() { ContentValues values = new ContentValues(); values.put(Email.DATA, email); values.put(Email.TYPE, Email.TYPE_WORK); return values; }
From source file:com.citrus.sdk.database.DBHandler.java
public void addBankOptions(JSONArray netbankingOption) { SQLiteDatabase db = this.getWritableDatabase(); for (int i = 0; i < netbankingOption.length(); i++) { ContentValues loadValue = new ContentValues(); try {// w w w . j ava 2 s .c o m JSONObject bankOption = netbankingOption.getJSONObject(i); loadValue.put(BANK, bankOption.getString("bankName")); loadValue.put(BANK_CID, bankOption.getString("issuerCode")); } catch (JSONException e) { } db.insert(BANK_TABLE, null, loadValue); } }
From source file:net.ccghe.emocha.model.DBAdapter.java
public static boolean markForDownload(String path, String newMD5) { ContentValues values = new ContentValues(); values.put("to_download", 1); values.put("md5", newMD5); return sDB.update(TABLE_DOWNLOADS, values, "path='" + path + "'", null) > 0; }
From source file:com.piusvelte.sonet.core.SonetNotifications.java
@Override public boolean onContextItemSelected(final MenuItem item) { if (item.getItemId() == CLEAR) { final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() { @Override// ww w . j a v a 2 s . c om protected Void doInBackground(Void... arg0) { // clear all notifications ContentValues values = new ContentValues(); values.put(Notifications.CLEARED, 1); SonetNotifications.this.getContentResolver().update( Notifications.getContentUri(SonetNotifications.this), values, Notifications._ID + "=?", new String[] { Long.toString(((AdapterContextMenuInfo) item.getMenuInfo()).id) }); return null; } @Override protected void onPostExecute(Void result) { if (loadingDialog.isShowing()) { loadingDialog.dismiss(); } SonetNotifications.this.finish(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); loadingDialog.show(); asyncTask.execute(); } return super.onContextItemSelected(item); // clear }
From source file:de.uhrenbastler.watchcheck.ui.LogDialog.java
/** * Creates the log entry in the content provider */// w ww .jav a 2s .c om protected void makeLogEntry() { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); double ntpDiff = modeNtp ? ((double) (localTime.getTimeInMillis() - ntpTime.getTimeInMillis())) / 1000d : 0; // Really??? ContentValues values = new ContentValues(); values.put(Logs.COMMENT, comment.getEditableText().toString()); values.put(Logs.DEVIATION, deviation); values.put(Logs.FLAG_RESET, startFlag.isChecked()); values.put(Logs.LOCAL_TIMESTAMP, dateFormat.format(localTime.getTime())); values.put(Logs.MODUS, modeNtp); values.put(Logs.NTP_DIFF, ntpDiff); if (positionSpinner.getSelectedItemId() > 0) values.put(Logs.POSITION, POSITIONARR[(int) positionSpinner.getSelectedItemId()]); if (temperatureSpinner.getSelectedItemId() > 0) values.put(Logs.TEMPERATURE, TEMPARR[(int) temperatureSpinner.getSelectedItemId()]); values.put(Logs.WATCH_ID, watchId); Logger.debug("values=" + values); getContext().getContentResolver().insert(Logs.CONTENT_URI, values); }
From source file:applab.search.client.JsonSimpleParser.java
/** * @param rowId/*from w w w . j a v a2s .c o m*/ * @param order * @param category * @param attribution * @param updated * @param keyword * @param content */ public void addRecord(String rowId, String order, String category, String attribution, String updated, String keyword, String content) { ContentValues addValues = new ContentValues(); // Split keyword String[] keywords = keyword.split(" "); for (int j = 0; j < keywords.length; j++) { addValues.put("col" + Integer.toString(j), keywords[j].replace("_", " ")); } addValues.put("id", rowId); addValues.put("position", order); addValues.put("content", content); storage.insertContent(GlobalConstants.MENU_ITEM_TABLE_NAME, addValues); }
From source file:com.mobile.system.db.abatis.AbatisService.java
public boolean insert(String tableName, Map<String, Object> bindParams) { getDbObject();/*w w w . ja v a2 s. com*/ ContentValues initialValues = new ContentValues(); if (bindParams != null) { Iterator<String> mapIterator = bindParams.keySet().iterator(); while (mapIterator.hasNext()) { String key = mapIterator.next(); Object value = bindParams.get(key); if (value instanceof byte[]) { initialValues.put(key, (byte[]) value); } else { initialValues.put(key, value.toString()); } } } int nInsertCnt = (int) dbObj.insert(tableName, null, initialValues); dbObj.close(); if (nInsertCnt <= 0) { return false; } return true; }
From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java
@Deprecated public static void sendMessage(final Context c, final Collection<Contact> contacts, final DbObject obj) { Uri url = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/out"); ContentValues values = new ContentValues(); values.put(DbObject.JSON, obj.getJson().toString()); values.put(DbObject.TYPE, obj.getType()); byte[] raw = obj.getRaw(); if (raw != null) { values.put(DbObject.RAW, raw);// w w w.ja va2s . co m } String to = buildAddresses(contacts); values.put(DbObject.DESTINATION, to); c.getContentResolver().insert(url, values); }
From source file:github.popeen.dsub.util.SongDBHandler.java
protected synchronized void addSongImpl(SQLiteDatabase db, int serverKey, String id, String absolutePath) { ContentValues values = new ContentValues(); values.put(SONGS_SERVER_KEY, serverKey); values.put(SONGS_SERVER_ID, id);/*from w w w . j a va2 s . c o m*/ values.put(SONGS_COMPLETE_PATH, absolutePath); db.insertWithOnConflict(TABLE_SONGS, null, values, SQLiteDatabase.CONFLICT_IGNORE); }