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:com.sip.pwc.sipphone.ui.filters.AccountFiltersListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Use custom drag and drop view -- reuse the one of accounts_edit_list
    View v = inflater.inflate(R.layout.accounts_edit_list, container, false);

    final DragnDropListView lv = (DragnDropListView) v.findViewById(android.R.id.list);

    lv.setGrabberId(R.id.grabber);//from   w w  w.j a v a2 s.c  om
    // Setup the drop listener
    lv.setOnDropListener(new DragnDropListView.DropListener() {
        @Override
        public void drop(int from, int to) {
            Log.d(THIS_FILE, "Drop from " + from + " to " + to);
            int hvC = lv.getHeaderViewsCount();
            from = Math.max(0, from - hvC);
            to = Math.max(0, to - hvC);

            int i;
            // First of all, compute what we get before move
            ArrayList<Long> orderedList = new ArrayList<Long>();
            CursorAdapter ad = (CursorAdapter) getListAdapter();
            for (i = 0; i < ad.getCount(); i++) {
                orderedList.add(ad.getItemId(i));
            }
            // Then, invert in the current list the two items ids
            Long moved = orderedList.remove(from);
            orderedList.add(to, moved);

            // Finally save that in db
            ContentResolver cr = getActivity().getContentResolver();
            for (i = 0; i < orderedList.size(); i++) {
                Uri uri = ContentUris.withAppendedId(SipManager.FILTER_ID_URI_BASE, orderedList.get(i));
                ContentValues cv = new ContentValues();
                cv.put(Filter.FIELD_PRIORITY, i);
                cr.update(uri, cv, null, null);
            }
        }
    });

    OnClickListener addClickButtonListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            onClickAddFilter();
        }
    };
    // Header view
    mHeaderView = inflater.inflate(R.layout.generic_add_header_list, container, false);
    mHeaderView.setOnClickListener(addClickButtonListener);
    ((TextView) mHeaderView.findViewById(R.id.text)).setText(R.string.add_filter);

    // Empty view
    Button bt = (Button) v.findViewById(android.R.id.empty);
    bt.setText(R.string.add_filter);
    bt.setOnClickListener(addClickButtonListener);

    return v;
}

From source file:net.fred.feedex.fragment.EntryFragment.java

private void refreshUI(Cursor entryCursor) {
    if (entryCursor != null) {
        String feedTitle = entryCursor.isNull(mFeedNamePos) ? entryCursor.getString(mFeedUrlPos)
                : entryCursor.getString(mFeedNamePos);
        BaseActivity activity = (BaseActivity) getActivity();
        activity.setTitle(feedTitle);/*from w  w w .  j ava2  s .  co m*/

        byte[] iconBytes = entryCursor.getBlob(mFeedIconPos);
        Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24);
        if (bitmap != null) {
            activity.getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap));
        } else {
            activity.getActionBar().setIcon(R.drawable.icon);
        }

        mFavorite = entryCursor.getInt(mIsFavoritePos) == 1;
        activity.invalidateOptionsMenu();

        // Listen the mobilizing task
        if (FetcherService.hasMobilizationTask(mEntriesIds[mCurrentPagerPos])) {
            showSwipeProgress();
        } else {
            hideSwipeProgress();
        }

        // Mark the article as read
        if (entryCursor.getInt(mIsReadPos) != 1) {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getReadContentValues(), null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }).start();
        }
    }
}

From source file:com.csipsimple.ui.filters.AccountFiltersListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Use custom drag and drop view -- reuse the one of accounts_edit_list
    View v = inflater.inflate(R.layout.accounts_edit_list, container, false);

    final DragnDropListView lv = (DragnDropListView) v.findViewById(android.R.id.list);

    lv.setGrabberId(R.id.grabber);/* w  w w  . j  a v a2s. c  o m*/
    // Setup the drop listener
    lv.setOnDropListener(new DropListener() {
        @Override
        public void drop(int from, int to) {
            Log.d(THIS_FILE, "Drop from " + from + " to " + to);
            int hvC = lv.getHeaderViewsCount();
            from = Math.max(0, from - hvC);
            to = Math.max(0, to - hvC);

            int i;
            // First of all, compute what we get before move
            ArrayList<Long> orderedList = new ArrayList<Long>();
            CursorAdapter ad = (CursorAdapter) getListAdapter();
            for (i = 0; i < ad.getCount(); i++) {
                orderedList.add(ad.getItemId(i));
            }
            // Then, invert in the current list the two items ids
            Long moved = orderedList.remove(from);
            orderedList.add(to, moved);

            // Finally save that in db
            ContentResolver cr = getActivity().getContentResolver();
            for (i = 0; i < orderedList.size(); i++) {
                Uri uri = ContentUris.withAppendedId(SipManager.FILTER_ID_URI_BASE, orderedList.get(i));
                ContentValues cv = new ContentValues();
                cv.put(Filter.FIELD_PRIORITY, i);
                cr.update(uri, cv, null, null);
            }
        }
    });

    OnClickListener addClickButtonListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            onClickAddFilter();
        }
    };
    // Header view
    mHeaderView = inflater.inflate(R.layout.generic_add_header_list, container, false);
    mHeaderView.setOnClickListener(addClickButtonListener);
    ((TextView) mHeaderView.findViewById(R.id.text)).setText(R.string.add_filter);

    // Empty view
    Button bt = (Button) v.findViewById(android.R.id.empty);
    bt.setText(R.string.add_filter);
    bt.setOnClickListener(addClickButtonListener);

    return v;
}

From source file:com.fututel.ui.filters.AccountFiltersListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Use custom drag and drop view -- reuse the one of accounts_edit_list
    View v = inflater.inflate(R.layout.accounts_edit_list, container, false);

    final DragnDropListView lv = (DragnDropListView) v.findViewById(android.R.id.list);

    lv.setGrabberId(R.id.grabber);/*  w  w  w.j  a va2s . c  o  m*/
    // Setup the drop listener
    lv.setOnDropListener(new DropListener() {
        @Override
        public void drop(int from, int to) {
            Log.d(THIS_FILE, "Drop from " + from + " to " + to);
            int hvC = lv.getHeaderViewsCount();
            from = Math.max(0, from - hvC);
            to = Math.max(0, to - hvC);

            int i;
            // First of all, compute what we get before move
            ArrayList<Long> orderedList = new ArrayList<Long>();
            CursorAdapter ad = (CursorAdapter) getListAdapter();
            for (i = 0; i < ad.getCount(); i++) {
                orderedList.add(ad.getItemId(i));
            }
            // Then, invert in the current list the two items ids
            Long moved = orderedList.remove(from);
            orderedList.add(to, moved);

            // Finally save that in db
            ContentResolver cr = getActivity().getContentResolver();
            for (i = 0; i < orderedList.size(); i++) {
                Uri uri = ContentUris.withAppendedId(SipManager.FILTER_ID_URI_BASE, orderedList.get(i));
                ContentValues cv = new ContentValues();
                cv.put(Filter.FIELD_PRIORITY, i);
                cr.update(uri, cv, null, null);
            }
        }
    });

    OnClickListener addClickButtonListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            onClickAddFilter();
        }
    };
    // Header view
    mHeaderView = inflater.inflate(R.layout.generic_add_header_list, container, false);
    mHeaderView.setOnClickListener(addClickButtonListener); //rangdong
    ((TextView) mHeaderView.findViewById(R.id.text)).setText(R.string.add_filter);

    // Empty view
    Button bt = (Button) v.findViewById(android.R.id.empty);
    bt.setText(R.string.add_filter);
    bt.setOnClickListener(addClickButtonListener);

    return v;
}

From source file:com.roamprocess1.roaming4world.ui.filters.AccountFiltersListFragment.java

@SuppressLint("WrongViewCast")
@Override//from w w  w  . j  av a  2  s.co m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Use custom drag and drop view -- reuse the one of accounts_edit_list
    View v = inflater.inflate(R.layout.accounts_edit_list, container, false);

    final DragnDropListView lv = (DragnDropListView) v.findViewById(android.R.id.list);

    lv.setGrabberId(R.id.grabber);
    // Setup the drop listener
    lv.setOnDropListener(new DropListener() {
        @Override
        public void drop(int from, int to) {
            Log.d(THIS_FILE, "Drop from " + from + " to " + to);
            int hvC = lv.getHeaderViewsCount();
            from = Math.max(0, from - hvC);
            to = Math.max(0, to - hvC);

            int i;
            // First of all, compute what we get before move
            ArrayList<Long> orderedList = new ArrayList<Long>();
            CursorAdapter ad = (CursorAdapter) getListAdapter();
            for (i = 0; i < ad.getCount(); i++) {
                orderedList.add(ad.getItemId(i));
            }
            // Then, invert in the current list the two items ids
            Long moved = orderedList.remove(from);
            orderedList.add(to, moved);

            // Finally save that in db
            ContentResolver cr = getActivity().getContentResolver();
            for (i = 0; i < orderedList.size(); i++) {
                Uri uri = ContentUris.withAppendedId(SipManager.FILTER_ID_URI_BASE, orderedList.get(i));
                ContentValues cv = new ContentValues();
                cv.put(Filter.FIELD_PRIORITY, i);
                cr.update(uri, cv, null, null);
            }
        }
    });

    OnClickListener addClickButtonListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            onClickAddFilter();
        }
    };
    // Header view
    mHeaderView = inflater.inflate(R.layout.generic_add_header_list, container, false);
    mHeaderView.setOnClickListener(addClickButtonListener);
    ((TextView) mHeaderView.findViewById(R.id.text)).setText(R.string.add_filter);

    // Empty view
    Button bt = (Button) v.findViewById(android.R.id.empty);
    bt.setText(R.string.add_filter);
    bt.setOnClickListener(addClickButtonListener);

    return v;
}

From source file:com.technoxist.fragment.EntryFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mEntriesIds != null) {
        Activity activity = getActivity();

        switch (item.getItemId()) {
        case R.id.menu_star: {
            mFavorite = !mFavorite;//from ww w .j a va  2s.  c o m

            if (mFavorite) {
                item.setIcon(R.drawable.rating_important);
            } else {
                item.setTitle(R.string.menu_star).setIcon(R.drawable.rating_not_important);
            }

            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentValues values = new ContentValues();
                    values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0);
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, values, null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }.start();
            break;
        }
        case R.id.menu_share: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            String link = cursor.getString(mLinkPos);
            if (link != null) {
                String title = cursor.getString(mTitlePos);
                startActivity(Intent.createChooser(
                        new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title)
                                .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN),
                        getString(R.string.menu_share)));
            }
            break;
        }
        case R.id.menu_full_screen: {
            setImmersiveFullScreen(true);
            break;
        }
        case R.id.menu_copy_clipboard: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            String link = cursor.getString(mLinkPos);
            ClipboardManager clipboard = (ClipboardManager) activity
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Copied Text", link);
            clipboard.setPrimaryClip(clip);

            Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show();
            break;
        }
        case R.id.menu_mark_as_unread: {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getUnreadContentValues(), null, null);
                }
            }.start();
            activity.finish();
            break;
        }
        }
    }

    return true;
}

From source file:com.viktorrudometkin.burramys.fragment.EntryFragment.java

private void refreshUI(Cursor entryCursor) {
    if (entryCursor != null) {
        String feedTitle = entryCursor.isNull(mFeedNamePos) ? entryCursor.getString(mFeedUrlPos)
                : entryCursor.getString(mFeedNamePos);
        BaseActivity activity = (BaseActivity) getActivity();
        activity.setTitle(feedTitle);/*  w ww.  j  ava 2 s  .  c om*/

        mFavorite = entryCursor.getInt(mIsFavoritePos) == 1;
        activity.invalidateOptionsMenu();

        // Listen the mobilizing task
        if (FetcherService.hasMobilizationTask(mEntriesIds[mCurrentPagerPos])) {
            showSwipeProgress();

            // If the service is not started, start it here to avoid an infinite loading
            if (!PrefUtils.getBoolean(PrefUtils.IS_REFRESHING, false)) {
                MainApplication.getContext()
                        .startService(new Intent(MainApplication.getContext(), FetcherService.class)
                                .setAction(FetcherService.ACTION_MOBILIZE_FEEDS));
            }
        } else {
            hideSwipeProgress();
        }

        // Mark the article as read
        if (entryCursor.getInt(mIsReadPos) != 1) {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getReadContentValues(), null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }).start();
        }
    }
}

From source file:com.app.uafeed.fragment.EntryFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mEntriesIds != null) {
        Activity activity = getActivity();

        switch (item.getItemId()) {
        case R.id.menu_star: {
            mFavorite = !mFavorite;//  w  w w  . ja  va 2 s . c om

            if (mFavorite) {
                item.setTitle(R.string.menu_unstar).setIcon(R.drawable.rating_important);
            } else {
                item.setTitle(R.string.menu_star).setIcon(R.drawable.rating_not_important);
            }

            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentValues values = new ContentValues();
                    values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0);
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, values, null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }.start();
            break;
        }
        case R.id.menu_share: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            String link = cursor.getString(mLinkPos);
            if (link != null) {
                String title = cursor.getString(mTitlePos);
                startActivity(Intent.createChooser(
                        new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title)
                                .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN),
                        getString(R.string.menu_share)));
            }
            break;
        }
        case R.id.menu_full_screen: {
            toggleFullScreen();
            break;
        }
        case R.id.menu_copy_clipboard: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            String link = cursor.getString(mLinkPos);
            ClipboardManager clipboard = (ClipboardManager) activity
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Copied Text", link);
            clipboard.setPrimaryClip(clip);

            Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show();
            break;
        }
        case R.id.menu_mark_as_unread: {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getUnreadContentValues(), null, null);
                }
            }.start();
            activity.finish();
            break;
        }
        }
    }

    return true;
}

From source file:com.manning.androidhacks.hack023.dao.TodoDAO.java

public int deleteTodo(ContentResolver contentResolver, Long id) {
    int ret = 0;/* w ww  .  j a va 2 s. c  om*/

    /* Using the local id */
    int status = getTodoStatus(contentResolver, id);

    switch (status) {
    case StatusFlag.ADD:
        ret = contentResolver.delete(TodoContentProvider.CONTENT_URI, TodoContentProvider.COLUMN_ID + "=" + id,
                null);
        break;
    case StatusFlag.MOD:
    case StatusFlag.CLEAN:
        ContentValues cv = new ContentValues();
        cv.put(TodoContentProvider.COLUMN_STATUS_FLAG, StatusFlag.DELETE);
        contentResolver.update(TodoContentProvider.CONTENT_URI, cv, TodoContentProvider.COLUMN_ID + "=" + id,
                null);
        break;
    default:
        throw new RuntimeException("Tried to delete a todo with invalid status");
    }

    return ret;
}

From source file:myblog.richard.vewe.launcher3.LauncherApplication.java

public void enableParentControl(boolean enable) {
    if (mUser == null)
        return;/*  w w  w. j  a  va 2s .c  om*/

    int flag = (Integer) mUser.getProperities().get(UsersContract.TableUsers.Column.FLAG);
    if (enable) {
        flag = UsersContract.TableUsers.enableParentControl(flag);
    } else {
        flag = UsersContract.TableUsers.disableParentControl(flag);
    }
    //update flag to content provider
    ContentResolver resolver = getContentResolver();

    ContentValues update = new ContentValues();

    update.put(UsersContract.TableUsers.Column.FLAG, flag);

    int rowsUpdated;
    String selection = UsersContract.TableUsers.Column.NAME + "=" + UsersContract.TableUsers.CURRENT;
    rowsUpdated = resolver.update(UsersContract.TableUsers.CONTENT_URI, update, selection, null);
    if (rowsUpdated != 1) {
        Log.e(tag, "failed to update the current user flag");
    } else {
        mUser.getProperities().put(UsersContract.TableUsers.Column.FLAG, flag);
        mService.updateUserSetting();
    }
}