List of usage examples for android.content ContentValues size
public int size()
From source file:Main.java
public static List<NameValuePair> convertParams(ContentValues params) { if (params == null || params.size() == 0) return null; List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); Set<Entry<String, Object>> setEntry = params.valueSet(); BasicNameValuePair bnvp = null;//from w ww . jav a2 s .com for (Entry<String, Object> entry : setEntry) { bnvp = new BasicNameValuePair(entry.getKey(), entry.getValue().toString()); nameValuePairs.add(bnvp); } return nameValuePairs; }
From source file:Main.java
public static String buildString(ContentValues params) { if (params == null || params.size() == 0) return null; Set<Entry<String, Object>> setEntry = params.valueSet(); StringBuilder sb = new StringBuilder(); for (Entry<String, Object> entry : setEntry) { sb.append(entry.getKey());/*w w w . j a v a2 s .c om*/ sb.append("="); sb.append(entry.getValue()); } return sb.toString(); }
From source file:com.wheelly.fragments.LocationsListFragment.java
private boolean handleContextItem(int itemId, final long id) { switch (itemId) { case MENU_RESOLVE: startGeocode(new LocationBroker(getActivity()).loadOrCreate(id)); return true; case MENU_EDIT: onListItemClick(getListView(), null, 0, id); return true; case MENU_DELETE: getActivity().getContentResolver().delete(Locations.CONTENT_URI, BaseColumns._ID + " = ?", new String[] { Long.toString(id) }); return true; case MENU_COLOR: new ColorInput(new OnSelectColorListener() { @Override/*from w ww .j av a 2 s .c o m*/ public void onSelect(DialogInterface dialog, int which, int color, String argb) { final LocationBroker broker = new LocationBroker(getActivity()); final ContentValues location = broker.loadOrCreate(id); if (location.size() > 0) { location.put("color", argb); broker.updateOrInsert(location); } } }).show(getFragmentManager(), null); return true; } ; return false; }
From source file:org.barbon.mangaget.fragments.MangaDetails.java
private void reload() { DB db = DB.getInstance(getActivity()); ContentValues manga = db.getManga(currentManga); ContentValues metadata = db.getMangaMetadata(currentManga); List<Integer> missingList = new ArrayList<Integer>(); int lastChapter = Utils.mangaChapterInfo(getActivity(), currentManga, missingList); title.setText(manga.getAsString(DB.MANGA_TITLE)); if (metadata.size() != 0) { setInProgress(false);// w w w . j a v a 2 s .c o m if (metadata.containsKey("genres")) genres.setText(metadata.getAsString("genres")); else genres.setText(R.string.not_available); if (metadata.containsKey("summary")) summary.setText(metadata.getAsString("summary")); else summary.setText(R.string.not_available); last.setText(Utils.formatChapterNumber(lastChapter)); if (missingList.size() > 0) { missing.setVisibility(View.VISIBLE); missing_label.setVisibility(View.VISIBLE); missing.setText(Utils.formatMissingChapters(missingList)); } else { missing.setVisibility(View.GONE); missing_label.setVisibility(View.GONE); } } else { Download.startMangaUpdate(getActivity(), currentManga); } }
From source file:org.mozilla.gecko.db.LocalURLMetadata.java
/** * Saves a HashMap of metadata into the database. Will iterate through columns * in the Database and only save rows with matching keys in the HashMap. * Must not be called from UI or Gecko threads. */// w ww . j a v a2 s .c om @Override public void save(final ContentResolver cr, final String url, final Map<String, Object> data) { ThreadUtils.assertNotOnUiThread(); ThreadUtils.assertNotOnGeckoThread(); try { ContentValues values = new ContentValues(); Set<String> model = getModel(); for (String key : model) { if (data.containsKey(key)) { values.put(key, (String) data.get(key)); } } if (values.size() == 0) { return; } Uri uri = uriWithProfile.buildUpon() .appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true").build(); cr.update(uri, values, URLMetadataTable.URL_COLUMN + "=?", new String[] { (String) data.get(URLMetadataTable.URL_COLUMN) }); } catch (Exception ex) { Log.e(LOGTAG, "error saving", ex); } }
From source file:com.granita.contacticloudsync.syncadapter.TasksSyncManager.java
@Override protected void queryCapabilities() throws DavException, IOException, HttpException, CalendarStorageException { davCollection.propfind(0, DisplayName.NAME, CalendarColor.NAME, GetCTag.NAME); // update name and color log.info("Setting task list name and color (if available)"); ContentValues values = new ContentValues(2); DisplayName pDisplayName = (DisplayName) davCollection.properties.get(DisplayName.NAME); if (pDisplayName != null && !TextUtils.isEmpty(pDisplayName.displayName)) values.put(TaskLists.LIST_NAME, pDisplayName.displayName); CalendarColor pColor = (CalendarColor) davCollection.properties.get(CalendarColor.NAME); if (pColor != null && pColor.color != null) values.put(TaskLists.LIST_COLOR, pColor.color); if (values.size() > 0) localTaskList().update(values);/*w w w .ja v a2 s . c o m*/ }
From source file:com.granita.contacticloudsync.syncadapter.CalendarSyncManager.java
@Override protected void queryCapabilities() throws DavException, IOException, HttpException, CalendarStorageException { davCollection.propfind(0, DisplayName.NAME, CalendarColor.NAME, GetCTag.NAME); // update name and color log.info("Setting calendar name and color (if available)"); ContentValues values = new ContentValues(2); DisplayName pDisplayName = (DisplayName) davCollection.properties.get(DisplayName.NAME); if (pDisplayName != null && !TextUtils.isEmpty(pDisplayName.displayName)) values.put(Calendars.CALENDAR_DISPLAY_NAME, pDisplayName.displayName); CalendarColor pColor = (CalendarColor) davCollection.properties.get(CalendarColor.NAME); if (pColor != null && pColor.color != null) values.put(Calendars.CALENDAR_COLOR, pColor.color); if (values.size() > 0) localCalendar().update(values);//from w ww . j a v a2 s . com }
From source file:at.bitfire.davdroid.resource.LocalTaskList.java
@Override public void updateMetaData(WebDavResource.Properties properties) throws LocalStorageException { ContentValues values = new ContentValues(); final String displayName = properties.getDisplayName(); if (displayName != null) values.put(TaskContract.TaskLists.LIST_NAME, displayName); final Integer color = properties.getColor(); if (color != null) values.put(TaskContract.TaskLists.LIST_COLOR, color); try {/*from w ww. j a va 2 s.co m*/ if (values.size() > 0) providerClient.update(ContentUris.withAppendedId(taskListsURI(account), id), values, null, null); } catch (RemoteException e) { throw new LocalStorageException(e); } }
From source file:org.totschnig.myexpenses.sync.SyncAdapter.java
@VisibleForTesting public void collectOperations(@NonNull TransactionChange change, long accountId, ArrayList<ContentProviderOperation> ops, int parentOffset) { Uri uri = Transaction.CALLER_IS_SYNC_ADAPTER_URI; switch (change.type()) { case created: ops.addAll(getContentProviderOperationsForCreate(change, ops.size(), parentOffset)); break;/*from ww w . ja v a 2 s. com*/ case updated: ContentValues values = toContentValues(change); if (values.size() > 0) { ops.add(ContentProviderOperation.newUpdate(uri) .withSelection(KEY_UUID + " = ? AND " + KEY_ACCOUNTID + " = ?", new String[] { change.uuid(), String.valueOf(accountId) }) .withValues(values).build()); } break; case deleted: ops.add(ContentProviderOperation.newDelete(uri) .withSelection(KEY_UUID + " = ?", new String[] { change.uuid() }).build()); break; } if (change.splitParts() != null) { final int newParentOffset = ops.size() - 1; List<TransactionChange> splitPartsFiltered = filterDeleted(change.splitParts(), findDeletedUuids(Stream.of(change.splitParts()))); Stream.of(splitPartsFiltered).forEach(splitChange -> collectOperations(splitChange, accountId, ops, change.isCreate() ? newParentOffset : -1)); //back reference is only used when we insert a new split, for updating an existing split we search for its _id via its uuid } }
From source file:com.android.messaging.datamodel.BugleDatabaseOperations.java
@DoesNotRunOnMainThread public static boolean updateRowIfExists(final DatabaseWrapper db, final String table, final String rowKey, final String rowId, final ContentValues values) { Assert.isNotMainThread();/*from www.j a v a2s .c om*/ final StringBuilder sb = new StringBuilder(); final ArrayList<String> whereValues = new ArrayList<String>(values.size() + 1); whereValues.add(rowId); for (final String key : values.keySet()) { if (sb.length() > 0) { sb.append(" OR "); } final Object value = values.get(key); sb.append(key); if (value != null) { sb.append(" IS NOT ?"); whereValues.add(value.toString()); } else { sb.append(" IS NOT NULL"); } } final String whereClause = rowKey + "=?" + " AND (" + sb.toString() + ")"; final String[] whereValuesArray = whereValues.toArray(new String[whereValues.size()]); final int count = db.update(table, values, whereClause, whereValuesArray); if (count > 1) { LogUtil.w(LogUtil.BUGLE_TAG, "Updated more than 1 row " + count + "; " + table + " for " + rowKey + " = " + rowId + " (deleted?)"); } Assert.inRange(count, 0, 1); return (count >= 0); }