List of usage examples for android.content ContentValues put
public void put(String key, byte[] value)
From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java
public static void deleteContact(final Context c, Long contactId) { /*c.getContentResolver().delete( Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts"), Contact._ID + "=?",//from w w w .j a v a 2 s. c om new String[]{ String.valueOf(contactId)}); */ Uri url = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts"); ContentValues values = new ContentValues(); values.put(Contact.HIDDEN, 1); c.getContentResolver().update(url, values, Contact._ID + "=" + contactId, null); }
From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java
/** * Add contacts to the group g. Send an invite to each contact * to join the private group feed./*from w ww . j a v a 2s . c om*/ */ public static void sendGroupInvite(final Context c, final long[] participants, final Group g) { ContentValues values = new ContentValues(); values.put("participants", Util.join(participants, ",")); values.put("groupName", g.name); values.put("dynUpdateUri", g.dynUpdateUri); values.put("groupId", g.id); Uri url = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/group_invitations"); c.getContentResolver().insert(url, values); }
From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java
public static Uri sendToFeed(Context c, Obj obj, Uri feed) { ContentValues values = new ContentValues(); values.put(DbObject.TYPE, obj.getType()); Object value = obj.getJson().toString(); if (value != null) { values.put(DbObject.JSON, (String) value); }//www. jav a 2s . c om value = obj.getRaw(); if (value != null) { values.put(DbObject.RAW, (byte[]) value); } return c.getContentResolver().insert(feed, values); }
From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java
@Deprecated public static Uri sendMessage(final Context c, long contactId, JSONObject json, String type) { Uri url = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/out"); Obj obj = DbObjects.convertOldJsonToObj(c, type, json); ContentValues values = new ContentValues(); values.put(DbObject.TYPE, type); values.put(DbObject.JSON, obj.getJson().toString()); if (obj.getRaw() != null) { values.put(DbObject.RAW, obj.getRaw()); }//from ww w.ja va2 s . c o m String to = Long.toString(contactId); values.put(DbObject.DESTINATION, to); return c.getContentResolver().insert(url, values); }
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 ww. jav a2 s . c om } String to = buildAddresses(contacts); values.put(DbObject.DESTINATION, to); c.getContentResolver().insert(url, values); }
From source file:export.FormCrawler.java
/** * For feed generation.../* w w w . jav a 2s .c o m*/ */ public static void setName(ContentValues c, String string) { // Jonas Oreland if (string.contains(" ")) { int index = string.indexOf(' '); c.put(DB.FEED.USER_FIRST_NAME, string.substring(0, index).trim()); c.put(DB.FEED.USER_LAST_NAME, string.substring(index).trim()); } else { c.put(DB.FEED.USER_FIRST_NAME, string); } }
From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java
/** * @see Helpers#sendToFeed(Context, Obj, Uri) *//*from w ww. j a v a 2s.c o m*/ @Deprecated public static Uri sendToFeed(Context c, DbObject obj, Uri feed) { ContentValues values = new ContentValues(); values.put(DbObject.TYPE, obj.getType()); DbEntryHandler objHandler = DbObjects.forType(obj.getType()); if (objHandler instanceof UnprocessedMessageHandler) { Pair<JSONObject, byte[]> r = ((UnprocessedMessageHandler) objHandler).handleUnprocessed(c, obj.getJson()); if (r != null) { values.put(DbObject.JSON, r.first.toString()); values.put(DbObject.RAW, r.second); } else { values.put(DbObject.JSON, obj.getJson().toString()); values.put(DbObject.RAW, obj.getRaw()); } } else { values.put(DbObject.JSON, obj.getJson().toString()); } return c.getContentResolver().insert(feed, values); }
From source file:at.bitfire.davdroid.resource.LocalTaskList.java
public static Uri create(Account account, ContentResolver resolver, ServerInfo.ResourceInfo info) throws LocalStorageException { @Cleanup("release") final ContentProviderClient client = resolver.acquireContentProviderClient(TASKS_AUTHORITY); if (client == null) throw new LocalStorageException("No tasks provider found"); ContentValues values = new ContentValues(); values.put(TaskContract.TaskLists.ACCOUNT_NAME, account.name); values.put(TaskContract.TaskLists.ACCOUNT_TYPE, account.type); values.put(TaskContract.TaskLists._SYNC_ID, info.getURL()); values.put(TaskContract.TaskLists.LIST_NAME, info.getTitle()); values.put(TaskContract.TaskLists.LIST_COLOR, info.getColor() != null ? info.getColor() : DAVUtils.calendarGreen); values.put(TaskContract.TaskLists.OWNER, account.name); values.put(TaskContract.TaskLists.ACCESS_LEVEL, 0); values.put(TaskContract.TaskLists.SYNC_ENABLED, 1); values.put(TaskContract.TaskLists.VISIBLE, 1); Log.i(TAG, "Inserting task list: " + values.toString()); try {//www . j a v a 2 s . c om return client.insert(taskListsURI(account), values); } catch (RemoteException e) { throw new LocalStorageException(e); } }
From source file:com.hichinaschool.flashcards.libanki.Storage.java
private static void _setColVars(AnkiDb db) { try {/*from ww w . j a v a 2 s.co m*/ JSONObject g = new JSONObject(Decks.defaultDeck); g.put("id", 1); g.put("name", "Default"); g.put("conf", 1); g.put("mod", Utils.intNow()); JSONObject gc = new JSONObject(Decks.defaultConf); gc.put("id", 1); JSONObject ag = new JSONObject(); ag.put("1", g); JSONObject agc = new JSONObject(); agc.put("1", gc); ContentValues values = new ContentValues(); values.put("conf", Collection.defaultConf); values.put("decks", Utils.jsonToString(ag)); values.put("dconf", Utils.jsonToString(agc)); db.update("col", values); } catch (JSONException e) { throw new RuntimeException(e); } }
From source file:com.android.exchange.adapter.Search.java
public static int searchMessages(Context context, long accountId, SearchParams searchParams, long destMailboxId) { // Sanity check for arguments final int offset = searchParams.mOffset; final int limit = searchParams.mLimit; final String filter = searchParams.mFilter; if (limit < 0 || limit > MAX_SEARCH_RESULTS || offset < 0) return 0; // TODO Should this be checked in UI? Are there guidelines for minimums? if (filter == null || filter.length() < MIN_QUERY_LENGTH) return 0; int res = 0;/*from w ww .j ava 2s . c om*/ final Account account = Account.restoreAccountWithId(context, accountId); if (account == null) return res; final EasSyncService svc = EasSyncService.setupServiceForAccount(context, account); if (svc == null) return res; final Mailbox searchMailbox = Mailbox.restoreMailboxWithId(context, destMailboxId); // Sanity check; account might have been deleted? if (searchMailbox == null) return res; final ContentValues statusValues = new ContentValues(2); try { // Set the status of this mailbox to indicate query statusValues.put(Mailbox.UI_SYNC_STATUS, UIProvider.SyncStatus.LIVE_QUERY); searchMailbox.update(context, statusValues); svc.mMailbox = searchMailbox; svc.mAccount = account; final Serializer s = new Serializer(); s.start(Tags.SEARCH_SEARCH).start(Tags.SEARCH_STORE); s.data(Tags.SEARCH_NAME, "Mailbox"); s.start(Tags.SEARCH_QUERY).start(Tags.SEARCH_AND); s.data(Tags.SYNC_CLASS, "Email"); // If this isn't an inbox search, then include the collection id final Mailbox inbox = Mailbox.restoreMailboxOfType(context, accountId, Mailbox.TYPE_INBOX); if (inbox == null) return 0; if (searchParams.mMailboxId != inbox.mId) { s.data(Tags.SYNC_COLLECTION_ID, inbox.mServerId); } s.data(Tags.SEARCH_FREE_TEXT, filter); // Add the date window if appropriate if (searchParams.mStartDate != null) { s.start(Tags.SEARCH_GREATER_THAN); s.tag(Tags.EMAIL_DATE_RECEIVED); s.data(Tags.SEARCH_VALUE, Eas.DATE_FORMAT.format(searchParams.mStartDate)); s.end(); // SEARCH_GREATER_THAN } if (searchParams.mEndDate != null) { s.start(Tags.SEARCH_LESS_THAN); s.tag(Tags.EMAIL_DATE_RECEIVED); s.data(Tags.SEARCH_VALUE, Eas.DATE_FORMAT.format(searchParams.mEndDate)); s.end(); // SEARCH_LESS_THAN } s.end().end(); // SEARCH_AND, SEARCH_QUERY s.start(Tags.SEARCH_OPTIONS); if (offset == 0) { s.tag(Tags.SEARCH_REBUILD_RESULTS); } if (searchParams.mIncludeChildren) { s.tag(Tags.SEARCH_DEEP_TRAVERSAL); } // Range is sent in the form first-last (e.g. 0-9) s.data(Tags.SEARCH_RANGE, offset + "-" + (offset + limit - 1)); s.start(Tags.BASE_BODY_PREFERENCE); s.data(Tags.BASE_TYPE, Eas.BODY_PREFERENCE_HTML); s.data(Tags.BASE_TRUNCATION_SIZE, "20000"); s.end(); // BASE_BODY_PREFERENCE s.end().end().end().done(); // SEARCH_OPTIONS, SEARCH_STORE, SEARCH_SEARCH final EasResponse resp = svc.sendHttpClientPost("Search", s.toByteArray()); try { final int code = resp.getStatus(); if (code == HttpStatus.SC_OK) { final InputStream is = resp.getInputStream(); try { final SearchParser sp = new SearchParser(is, svc, filter); sp.parse(); res = sp.getTotalResults(); } finally { is.close(); } } else { svc.userLog("Search returned " + code); } } finally { resp.close(); } } catch (IOException e) { svc.userLog("Search exception " + e); } finally { // TODO: Handle error states // Set the status of this mailbox to indicate query over statusValues.put(Mailbox.SYNC_TIME, System.currentTimeMillis()); statusValues.put(Mailbox.UI_SYNC_STATUS, UIProvider.SyncStatus.NO_SYNC); searchMailbox.update(context, statusValues); } // Return the total count return res; }