Example usage for android.content ContentResolver update

List of usage examples for android.content ContentResolver update

Introduction

In this page you can find the example usage for android.content ContentResolver update.

Prototype

public final int update(@RequiresPermission.Write @NonNull Uri uri, @Nullable ContentValues values,
        @Nullable String where, @Nullable String[] selectionArgs) 

Source Link

Document

Update row(s) in a content URI.

Usage

From source file:org.ale.scanner.zotero.data.BibItem.java

public void writeToDB(ContentResolver cr) {
    ContentValues values = toContentValues();
    if (mId == NO_ID) {
        Uri row = cr.insert(Database.BIBINFO_URI, values);
        int id = Integer.parseInt(row.getLastPathSegment());
        setId(id);/*  w  w  w.j a  v  a 2  s .  co m*/
    } else {
        cr.update(Database.BIBINFO_URI, values, BibItem._ID + "=?", new String[] { String.valueOf(mId) });
    }
}

From source file:org.androidpn.demoapp.MessageListActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Intent intent = new Intent(this, MessageDetailActivity.class);
    Bundle bundle = new Bundle();
    bundle.putSerializable("message", (Serializable) parent.getAdapter().getItem(position));
    intent.putExtras(bundle);/* w  w  w  .ja  v  a  2s . c  o m*/
    ((SingleMessage) parent.getAdapter().getItem(position)).setStatus(1);
    ContentResolver contentResolver = getContentResolver();
    ContentValues contentValues = new ContentValues();
    contentValues.put(MESSAGE_SUMMARY_PROJECTION[6], 1);
    contentResolver.update(ServerMessage.CONTENT_URI, contentValues, "message_id = ?",
            new String[] { ((SingleMessage) parent.getAdapter().getItem(position)).getId() });
    mAdapter.notifyDataSetChanged();
    startActivity(intent);
}

From source file:com.android.mail.utils.NotificationActionUtils.java

/**
 * Processes the specified destructive action (archive, delete, mute) on the message.
 *///from www .ja va  2 s .c o m
public static void processDestructiveAction(final Context context,
        final NotificationAction notificationAction) {
    LogUtils.i(LOG_TAG, "processDestructiveAction: %s", notificationAction.getNotificationActionType());

    final NotificationActionType destructAction = notificationAction.getNotificationActionType();
    final Conversation conversation = notificationAction.getConversation();
    final Folder folder = notificationAction.getFolder();

    final ContentResolver contentResolver = context.getContentResolver();
    final Uri uri = conversation.uri.buildUpon()
            .appendQueryParameter(UIProvider.FORCE_UI_NOTIFICATIONS_QUERY_PARAMETER, Boolean.TRUE.toString())
            .build();

    switch (destructAction) {
    case ARCHIVE_REMOVE_LABEL: {
        if (folder.isInbox()) {
            // Inbox, so archive
            final ContentValues values = new ContentValues(1);
            values.put(UIProvider.ConversationOperations.OPERATION_KEY,
                    UIProvider.ConversationOperations.ARCHIVE);

            contentResolver.update(uri, values, null, null);
        } else {
            // Not inbox, so remove label
            final ContentValues values = new ContentValues(1);

            final String removeFolderUri = folder.folderUri.fullUri.buildUpon()
                    .appendPath(Boolean.FALSE.toString()).toString();
            values.put(ConversationOperations.FOLDERS_UPDATED, removeFolderUri);

            contentResolver.update(uri, values, null, null);
        }
        break;
    }
    case DELETE: {
        contentResolver.delete(uri, null, null);
        break;
    }
    default:
        throw new IllegalArgumentException("The specified NotificationActionType is not a destructive action.");
    }
}

From source file:com.ultramegatech.ey.UpdateService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (!HttpHelper.isConnected(this)) {
        return;/*from  www  .  ja va  2 s . co m*/
    }

    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    final long lastCheck = preferences.getLong(KEY_LAST_CHECK, 0);
    final long now = System.currentTimeMillis();
    if (now - lastCheck < CHECK_INTERVAL) {
        return;
    }

    Log.v(TAG, "Checking for updates");

    final int version = preferences.getInt(KEY_VERSION, 0);
    final int newVersion = HttpHelper.getVersion();
    if (newVersion > version) {
        Log.v(TAG, "Downloading updates...");

        final ContentValues[] valuesArray = fetchElementData(newVersion);
        if (valuesArray == null) {
            return;
        }

        final ContentResolver cr = getContentResolver();
        Uri uri;
        int changed;
        for (int i = 0; i < valuesArray.length; i++) {
            uri = ContentUris.withAppendedId(Elements.CONTENT_URI_NUMBER,
                    valuesArray[i].getAsLong(Elements.NUMBER));
            changed = cr.update(uri, valuesArray[i], null, null);

            if (changed == 0) {
                cr.insert(Elements.CONTENT_URI, valuesArray[i]);
            }
        }

        preferences.edit().putInt(KEY_VERSION, newVersion).commit();

        Log.v(TAG, "Update completed successfully");
    }

    preferences.edit().putLong(KEY_LAST_CHECK, System.currentTimeMillis()).commit();
}

From source file:de.aw.awlib.gv.CalendarReminder.java

/**
 * Setzt ein neues Datum fuer einen Kalendereintrag
 *
 * @param eventID/*from  w  w w .  j ava  2 s .  c o  m*/
 *         ID des items des Kalenders
 * @param start
 *         Neues Datum
 * @return true, wenn erfolgreich
 */
public boolean updateEventDate(long eventID, Date start, Date end) {
    if (ContextCompat.checkSelfPermission(mContext,
            Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED) {
        ContentResolver cr = mContext.getContentResolver();
        ContentValues values = new ContentValues();
        values.put(CalendarContract.Events.DTSTART, start.getTime());
        values.put(CalendarContract.Events.DTEND, end.getTime());
        Uri updateUri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);
        return (cr.update(updateUri, values, null, null) != 0);
    }
    return false;
}

From source file:net.fred.feedex.adapter.EntriesCursorAdapter.java

public void markAllAsRead(final long untilDate) {
    new Thread() {
        @Override//from ww w. j  a va2 s .c o  m
        public void run() {
            ContentResolver cr = MainApplication.getContext().getContentResolver();
            String where = EntryColumns.WHERE_UNREAD + Constants.DB_AND + '(' + EntryColumns.FETCH_DATE
                    + Constants.DB_IS_NULL + Constants.DB_OR + EntryColumns.FETCH_DATE + "<=" + untilDate + ')';
            cr.update(mUri, FeedData.getReadContentValues(), where, null);
        }
    }.start();
}

From source file:com.murrayc.galaxyzoo.app.syncadapter.SyncAdapter.java

private void markItemAsUploaded(final String itemId) {
    final ContentValues values = new ContentValues();
    values.put(Item.Columns.UPLOADED, 1);

    final ContentResolver resolver = getContentResolver();
    final int affected = resolver.update(Utils.getItemUri(itemId), values, null, null);

    if (affected != 1) {
        Log.error("markItemAsUploaded(): Unexpected affected rows: " + affected);
    }// w  ww.j  a v a  2s  . co m
}

From source file:com.dabay6.android.apps.carlog.ui.base.fragments.BaseEditFragment.java

/**
 * {@inheritDoc}//  w  w  w  .  j a v  a2 s . com
 */
@Override
public void onPositiveButtonClick() {
    try {
        if (validator.validate()) {
            final ContentValues values = buildContentValues();
            final ContentResolver resolver = applicationContext.getContentResolver();

            if (isInsert) {
                resolver.insert(getUri(), values);
            } else {
                final String selection = getIdentityColumnName() + " = ?";
                final String[] selectionArgs = new String[] { entityId.toString() };

                resolver.update(getUri(), values, selection, selectionArgs);
            }

            clear();

            onEntityEditListener.onEntitySave();
        }
    } catch (Exception e) {
        Logger.error(TAG, e.getMessage(), e);
    }
}

From source file:com.nononsenseapps.notepad.MainActivity.java

/**
 * Delete all notes given from database Only marks them as deleted if sync
 * is enabled/*from w  w  w  .ja va  2s.com*/
 * 
 * @param ids
 */
public static void deleteNotes(Context context, Iterable<Long> ids) {
    ContentResolver resolver = context.getContentResolver();
    boolean shouldMark = shouldMarkAsDeleted(context);
    for (long id : ids) {
        Log.d(TAG, "deleteNotes: " + id);
        if (shouldMark) {
            ContentValues values = new ContentValues();
            values.put(NotePad.Notes.COLUMN_NAME_DELETED, "1");
            resolver.update(NotesEditorFragment.getUriFrom(id), values, null, null);
        } else {
            resolver.delete(NotesEditorFragment.getUriFrom(id), null, null);
        }
        UpdateNotifier.notifyChangeNote(context, NotesEditorFragment.getUriFrom(id));
    }
}

From source file:com.android.emailcommon.provider.Account.java

/**
 * Clear all account hold flags that are set.
 *
 * (This will trigger watchers, and in particular will cause EAS to try and resync the
 * account(s).)//  ww w.j a  v a  2 s .  c  o  m
 */
public static void clearSecurityHoldOnAllAccounts(Context context) {
    ContentResolver resolver = context.getContentResolver();
    Cursor c = resolver.query(Account.CONTENT_URI, ACCOUNT_FLAGS_PROJECTION, SECURITY_NONZERO_SELECTION, null,
            null);
    try {
        while (c.moveToNext()) {
            int flags = c.getInt(ACCOUNT_FLAGS_COLUMN_FLAGS);

            if (0 != (flags & FLAGS_SECURITY_HOLD)) {
                ContentValues cv = new ContentValues();
                cv.put(AccountColumns.FLAGS, flags & ~FLAGS_SECURITY_HOLD);
                long accountId = c.getLong(ACCOUNT_FLAGS_COLUMN_ID);
                Uri uri = ContentUris.withAppendedId(Account.CONTENT_URI, accountId);
                resolver.update(uri, cv, null, null);
            }
        }
    } finally {
        c.close();
    }
}