List of usage examples for android.content ContentValues ContentValues
public ContentValues()
From source file:org.noorganization.instalistsynch.controller.local.dba.impl.SqliteGroupAccessDbControllerTest.java
License:asdf
public void testGetGroupAuthAccesses() throws Exception { Date currentDate = new Date(); SQLiteDatabase db = mDbHelper.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put(GroupAccess.COLUMN.GROUP_ID, 1); cv.put(GroupAccess.COLUMN.INTERRUPTED, false); cv.put(GroupAccess.COLUMN.SYNCHRONIZE, true); cv.put(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.LAST_TOKEN_REQUEST, ISO8601Utils.format(currentDate)); cv.put(GroupAccess.COLUMN.TOKEN, "fdskhbvvkddscddueFSNDFSAdnandk3229df-dFSJDKMds."); assertTrue(db.insert(GroupAccess.TABLE_NAME, null, cv) >= 0); Date otherDate = new Date(); cv.put(GroupAccess.COLUMN.GROUP_ID, 2); cv.put(GroupAccess.COLUMN.INTERRUPTED, true); cv.put(GroupAccess.COLUMN.SYNCHRONIZE, true); cv.put(GroupAccess.COLUMN.LAST_UPDATE_FROM_SERVER, ISO8601Utils.format(otherDate)); cv.put(GroupAccess.COLUMN.LAST_TOKEN_REQUEST, ISO8601Utils.format(otherDate)); cv.put(GroupAccess.COLUMN.TOKEN, "fdskhbvvkddscddu3rssNDFSAdnandk3229df-dFSJDKMds."); assertTrue(db.insert(GroupAccess.TABLE_NAME, null, cv) >= 0); List<GroupAccess> groupAccessList = mGroupAuthAccessDbController.getGroupAuthAccesses(); assertNotNull(groupAccessList);/*from ww w . j a v a2 s .co m*/ assertEquals(2, groupAccessList.size()); for (GroupAccess groupAccess : groupAccessList) { assertNotNull(groupAccess); switch (groupAccess.getGroupId()) { case 1: assertEquals(1, groupAccess.getGroupId()); assertEquals(false, groupAccess.wasInterrupted()); assertEquals(true, groupAccess.isSynchronize()); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(groupAccess.getLastUpdateFromServer())); assertEquals(ISO8601Utils.format(currentDate), ISO8601Utils.format(groupAccess.getLastTokenRequest())); assertEquals("fdskhbvvkddscddueFSNDFSAdnandk3229df-dFSJDKMds.", groupAccess.getToken()); break; case 2: assertEquals(2, groupAccess.getGroupId()); assertEquals(true, groupAccess.wasInterrupted()); assertEquals(true, groupAccess.isSynchronize()); assertEquals(ISO8601Utils.format(otherDate), ISO8601Utils.format(groupAccess.getLastUpdateFromServer())); assertEquals(ISO8601Utils.format(otherDate), ISO8601Utils.format(groupAccess.getLastTokenRequest())); assertEquals("fdskhbvvkddscddu3rssNDFSAdnandk3229df-dFSJDKMds.", groupAccess.getToken()); break; default: assertTrue(false); } } }
From source file:com.mwebster.exchange.EasOutboxService.java
/** * Send a single message via EAS/*from w w w . j av a 2 s .c o m*/ * Note that we mark messages SEND_FAILED when there is a permanent failure, rather than an * IOException, which is handled by SyncManager with retries, backoffs, etc. * * @param cacheDir the cache directory for this context * @param msgId the _id of the message to send * @throws IOException */ int sendMessage(File cacheDir, long msgId) throws IOException, MessagingException { int result; sendCallback(msgId, null, EmailServiceStatus.IN_PROGRESS); File tmpFile = File.createTempFile("eas_", "tmp", cacheDir); // Write the output to a temporary file try { String[] cols = getRowColumns(Message.CONTENT_URI, msgId, MessageColumns.FLAGS, MessageColumns.SUBJECT); int flags = Integer.parseInt(cols[0]); String subject = cols[1]; boolean reply = (flags & Message.FLAG_TYPE_REPLY) != 0; boolean forward = (flags & Message.FLAG_TYPE_FORWARD) != 0; // The reference message and mailbox are called item and collection in EAS String itemId = null; String collectionId = null; if (reply || forward) { // First, we need to get the id of the reply/forward message cols = getRowColumns(Body.CONTENT_URI, BODY_SOURCE_PROJECTION, WHERE_MESSAGE_KEY, new String[] { Long.toString(msgId) }); if (cols != null) { long refId = Long.parseLong(cols[0]); // Then, we need the serverId and mailboxKey of the message cols = getRowColumns(Message.CONTENT_URI, refId, SyncColumns.SERVER_ID, MessageColumns.MAILBOX_KEY); if (cols != null) { itemId = cols[0]; long boxId = Long.parseLong(cols[1]); // Then, we need the serverId of the mailbox cols = getRowColumns(Mailbox.CONTENT_URI, boxId, MailboxColumns.SERVER_ID); if (cols != null) { collectionId = cols[0]; } } } } boolean smartSend = itemId != null && collectionId != null; // Write the message in rfc822 format to the temporary file FileOutputStream fileStream = new FileOutputStream(tmpFile); Rfc822Output.writeTo(mContext, msgId, fileStream, !smartSend, true); fileStream.close(); // Now, get an input stream to our temporary file and create an entity with it FileInputStream inputStream = new FileInputStream(tmpFile); InputStreamEntity inputEntity = new InputStreamEntity(inputStream, tmpFile.length()); // Create the appropriate command and POST it to the server String cmd = "SendMail&SaveInSent=T"; if (smartSend) { cmd = reply ? "SmartReply" : "SmartForward"; cmd += "&ItemId=" + itemId + "&CollectionId=" + collectionId + "&SaveInSent=T"; } userLog("Send cmd: " + cmd); HttpResponse resp = sendHttpClientPost(cmd, inputEntity, SEND_MAIL_TIMEOUT); inputStream.close(); int code = resp.getStatusLine().getStatusCode(); if (code == HttpStatus.SC_OK) { userLog("Deleting message..."); mContentResolver.delete(ContentUris.withAppendedId(Message.CONTENT_URI, msgId), null, null); result = EmailServiceStatus.SUCCESS; sendCallback(-1, subject, EmailServiceStatus.SUCCESS); } else { userLog("Message sending failed, code: " + code); ContentValues cv = new ContentValues(); cv.put(SyncColumns.SERVER_ID, SEND_FAILED); Message.update(mContext, Message.CONTENT_URI, msgId, cv); // We mark the result as SUCCESS on a non-auth failure since the message itself is // already marked failed and we don't want to stop other messages from trying to // send. if (isAuthError(code)) { result = EmailServiceStatus.LOGIN_FAILED; } else { result = EmailServiceStatus.SUCCESS; } sendCallback(msgId, null, result); } } catch (IOException e) { // We catch this just to send the callback sendCallback(msgId, null, EmailServiceStatus.CONNECTION_ERROR); throw e; } finally { // Clean up the temporary file if (tmpFile.exists()) { tmpFile.delete(); } } return result; }
From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java
public static void sendAppFeedInvite(Context c, Collection<Contact> contacts, String feedName, String packageName) {/*from ww w . j a v a 2 s . co m*/ Uri url = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/out"); ContentValues values = new ContentValues(); JSONObject obj = InviteToSharedAppFeedObj.json(contacts, feedName, packageName); values.put(DbObject.JSON, obj.toString()); values.put(DbObject.DESTINATION, buildAddresses(contacts)); values.put(DbObject.TYPE, InviteToSharedAppFeedObj.TYPE); c.getContentResolver().insert(url, values); }
From source file:com.android.server.MaybeDatabaseHelper.java
public int setData(String packagename, String data) { Log.v(DBTAG, "packagename=" + packagename + " data=" + data); if (data == null || packagename == null) return 0; int ret;//from ww w. j a v a 2s.c om synchronized (sAppTableLock) { final ContentValues c = new ContentValues(); c.put(DATA_COL, data); c.put(PUSH_COL, true); ret = sDatabase.update(APP_TABLE_NAME, c, PACKAGE_COL + "='" + packagename + "'", null); } Log.v(DBTAG, "Database value inserted" + getAppDataFromDb(DATA_COL, packagename)); return ret; }
From source file:com.nbos.phonebook.sync.platform.ContactManager.java
public static void updateNameOfExistingContact(Context context, Name ContactName, long rawContactId) { Log.i(tag, ContactName + " added"); ContentValues values = new ContentValues(); values.put(StructuredName.RAW_CONTACT_ID, rawContactId); values.put(StructuredName.PREFIX, ContactName.prefix); values.put(StructuredName.GIVEN_NAME, ContactName.given); values.put(StructuredName.MIDDLE_NAME, ContactName.middle); values.put(StructuredName.FAMILY_NAME, ContactName.family); values.put(StructuredName.SUFFIX, ContactName.suffix); values.put(StructuredName.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE); context.getContentResolver().insert(SyncManager.addCallerIsSyncAdapterParameter(Data.CONTENT_URI), values); }
From source file:com.tlongdev.bktf.interactor.TlongdevPriceListInteractor.java
private ContentValues buildContentValues(JsonParser parser) throws IOException { ContentValues values = new ContentValues(); int defindex = 0; int quality = 0; int tradable = 0; int craftable = 0; double value = 0; Double high = null;// w w w. jav a 2 s .c o m double raw = 0; while (parser.nextToken() != JsonToken.END_OBJECT) { parser.nextToken(); switch (parser.getCurrentName()) { case "defindex": Item item = new Item(); item.setDefindex(parser.getIntValue()); defindex = item.getFixedDefindex(); values.put(PriceEntry.COLUMN_DEFINDEX, defindex); break; case "quality": quality = parser.getIntValue(); values.put(PriceEntry.COLUMN_ITEM_QUALITY, quality); break; case "tradable": tradable = parser.getIntValue(); values.put(PriceEntry.COLUMN_ITEM_TRADABLE, tradable); break; case "craftable": craftable = parser.getIntValue(); values.put(PriceEntry.COLUMN_ITEM_CRAFTABLE, craftable); break; case "price_index": values.put(PriceEntry.COLUMN_PRICE_INDEX, parser.getIntValue()); break; case "australium": values.put(PriceEntry.COLUMN_AUSTRALIUM, parser.getIntValue()); break; case "currency": values.put(PriceEntry.COLUMN_CURRENCY, parser.getText()); break; case "value": value = parser.getDoubleValue(); values.put(PriceEntry.COLUMN_PRICE, value); break; case "value_high": high = parser.getDoubleValue(); values.put(PriceEntry.COLUMN_PRICE_HIGH, high); break; case "value_raw": raw = parser.getDoubleValue(); break; case "last_update": values.put(PriceEntry.COLUMN_LAST_UPDATE, parser.getLongValue()); break; case "difference": values.put(PriceEntry.COLUMN_DIFFERENCE, parser.getDoubleValue()); break; } } values.put(PriceEntry.COLUMN_WEAPON_WEAR, 0); if (quality == Quality.UNIQUE && tradable == 1 && craftable == 1) { if (defindex == 143) { //buds Utility.putDouble(mEditor, mContext.getString(R.string.pref_buds_raw), raw); mEditor.apply(); } else if (defindex == 5002) { //metal double highPrice = high == null ? 0 : high; if (highPrice > value) { //If the metal has a high price, save the average as raw. Utility.putDouble(mEditor, mContext.getString(R.string.pref_metal_raw_usd), ((value + highPrice) / 2)); } else { //save as raw price Utility.putDouble(mEditor, mContext.getString(R.string.pref_metal_raw_usd), value); } mEditor.apply(); } else if (defindex == 5021) { //key Utility.putDouble(mEditor, mContext.getString(R.string.pref_key_raw), raw); mEditor.apply(); } } return values; }
From source file:com.nononsenseapps.notepad.sync.googleapi.GoogleTask.java
/** * Returns a ContentValues hashmap suitable for database insertion in the * Lists table Includes modified flag and list id as specified in the * arguments/* www.j a v a2s . c o m*/ * * @return */ public ContentValues toNotesContentValues(int modified, long listDbId) { ContentValues values = new ContentValues(); if (title != null) values.put(NotePad.Notes.COLUMN_NAME_TITLE, title); if (dueDate != null) values.put(NotePad.Notes.COLUMN_NAME_DUE_DATE, dueDate); if (status != null) values.put(NotePad.Notes.COLUMN_NAME_GTASKS_STATUS, status); if (notes != null) values.put(NotePad.Notes.COLUMN_NAME_NOTE, notes); if (dbid > -1) values.put(NotePad.Notes._ID, dbid); values.put(NotePad.Notes.COLUMN_NAME_LIST, listDbId); values.put(NotePad.Notes.COLUMN_NAME_MODIFIED, modified); values.put(NotePad.Notes.COLUMN_NAME_DELETED, deleted); values.put(NotePad.Notes.COLUMN_NAME_POSITION, position); values.put(NotePad.Notes.COLUMN_NAME_PARENT, parent); //values.put(NotePad.Notes.COLUMN_NAME_HIDDEN, hidden); values.put(NotePad.Notes.COLUMN_NAME_POSSUBSORT, possort); //values.put(NotePad.Notes.COLUMN_NAME_INDENTLEVEL, indentLevel); return values; }
From source file:com.hichinaschool.flashcards.libanki.Decks.java
public void flush() { ContentValues values = new ContentValues(); if (mChanged) { try {// w w w . j a v a2s .c o m JSONObject decksarray = new JSONObject(); for (Map.Entry<Long, JSONObject> d : mDecks.entrySet()) { decksarray.put(Long.toString(d.getKey()), d.getValue()); } values.put("decks", Utils.jsonToString(decksarray)); JSONObject confarray = new JSONObject(); for (Map.Entry<Long, JSONObject> d : mDconf.entrySet()) { confarray.put(Long.toString(d.getKey()), d.getValue()); } values.put("dconf", Utils.jsonToString(confarray)); } catch (JSONException e) { throw new RuntimeException(e); } mCol.getDb().update("col", values); mChanged = false; } }
From source file:edu.nd.darts.cimon.database.CimonDatabaseAdapter.java
/** * Insert new reading into Data table.// w w w . ja va 2 s . co m * * @param metric id of metric * @param monitor id of monitor * @param timestamp timestamp measured from uptime (milliseconds) * @param value value of reading * @return rowid of inserted row, -1 on failure * * @see DataTable */ public synchronized long insertData(int metric, int monitor, long timestamp, float value) { if (DebugLog.DEBUG) Log.d(TAG, "CimonDatabaseAdapter.insertData - insert into Data table: metric-" + metric); ContentValues values = new ContentValues(); values.put(DataTable.COLUMN_METRIC_ID, metric); values.put(DataTable.COLUMN_MONITOR_ID, monitor); values.put(DataTable.COLUMN_TIMESTAMP, timestamp); values.put(DataTable.COLUMN_VALUE, value); long rowid = database.insert(DataTable.TABLE_DATA, null, values); if (rowid >= 0) { Uri uri = Uri.withAppendedPath(CimonContentProvider.DATA_URI, String.valueOf(rowid)); context.getContentResolver().notifyChange(uri, null); } return rowid; }
From source file:com.photowall.oauth.util.BaseHttpClient.java
/** * /*from www . j a v a 2s .c om*/ * @param mContext */ private void setProxy(Context mContext) { try { ContentValues values = new ContentValues(); Cursor cur = mContext.getContentResolver().query(Uri.parse("content://telephony/carriers/preferapn"), null, null, null, null); if (cur != null && cur.getCount() > 0) { if (cur.moveToFirst()) { int colCount = cur.getColumnCount(); for (int i = 0; i < colCount; i++) { values.put(cur.getColumnName(i), cur.getString(i)); } } cur.close(); } String proxyHost = (String) values.get("proxy"); if (!TextUtils.isEmpty(proxyHost) && !isWiFiConnected(mContext)) { int prot = Integer.parseInt(String.valueOf(values.get("port"))); delegate.getCredentialsProvider().setCredentials(new AuthScope(proxyHost, prot), new UsernamePasswordCredentials((String) values.get("user"), (String) values.get("password"))); HttpHost proxy = new HttpHost(proxyHost, prot); delegate.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } } catch (Exception e) { e.printStackTrace(); Log.w(TAG, "set proxy error+++++++++++++++++"); } }