Example usage for android.content ContentUris withAppendedId

List of usage examples for android.content ContentUris withAppendedId

Introduction

In this page you can find the example usage for android.content ContentUris withAppendedId.

Prototype

public static Uri withAppendedId(Uri contentUri, long id) 

Source Link

Document

Appends the given ID to the end of the path.

Usage

From source file:com.csipsimple.ui.account.AccountsEditListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Use custom drag and drop view
    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);/*  www . j  av a2s .  co  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
            if (getActivity() != null) {
                ContentResolver cr = getActivity().getContentResolver();
                for (i = 0; i < orderedList.size(); i++) {
                    Uri uri = ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, orderedList.get(i));
                    ContentValues cv = new ContentValues();
                    cv.put(SipProfile.FIELD_PRIORITY, i);
                    cr.update(uri, cv, null, null);
                }
            }
        }
    });

    OnClickListener addClickButtonListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            onClickAddAccount();
        }
    };
    // Header view
    mHeaderView = inflater.inflate(R.layout.generic_add_header_list, container, false);
    mHeaderView.setOnClickListener(addClickButtonListener);

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

    return v;
}

From source file:com.android.calendar.selectcalendars.SelectSyncedCalendarsMultiAccountAdapter.java

public void doSaveAction() {
    // Cancel the previous operation
    mCalendarsUpdater.cancelOperation(mUpdateToken);
    mUpdateToken++;/*w ww  .  j  a  va 2s  .c  om*/
    // This is to allow us to do queries and updates with the same AsyncQueryHandler without
    // accidently canceling queries.
    if (mUpdateToken < MIN_UPDATE_TOKEN) {
        mUpdateToken = MIN_UPDATE_TOKEN;
    }

    Iterator<Long> changeKeys = mCalendarChanges.keySet().iterator();
    while (changeKeys.hasNext()) {
        long id = changeKeys.next();
        boolean newSynced = mCalendarChanges.get(id);

        Uri uri = ContentUris.withAppendedId(Calendars.CONTENT_URI, id);
        ContentValues values = new ContentValues();
        values.put(Calendars.VISIBLE, newSynced ? 1 : 0);
        values.put(Calendars.SYNC_EVENTS, newSynced ? 1 : 0);
        mCalendarsUpdater.startUpdate(mUpdateToken, id, uri, values, null, null);
    }
}

From source file:com.frostwire.android.gui.adapters.FileListAdapter.java

private Uri[] getFileItemThumbnailUris(FileDescriptorItem item) {
    Uri[] uris = new Uri[2];
    if (item.fd.fileType == Constants.FILE_TYPE_VIDEOS) {
        uris[0] = ContentUris.withAppendedId(Video.Media.EXTERNAL_CONTENT_URI, item.fd.id);
        uris[1] = ImageLoader.getMetadataArtUri(uris[0]);
    } else if (item.fd.fileType == Constants.FILE_TYPE_PICTURES) {
        Uri uri = ContentUris.withAppendedId(Images.Media.EXTERNAL_CONTENT_URI, item.fd.id);
        uris[0] = uri;//  ww w  .  ja v  a  2  s. c  o  m
        uris[1] = null;
    }
    return uris;
}

From source file:ca.marcmeszaros.papyrus.browser.BooksBrowser.java

/**
 * Checks that there are enough books to loan out this copy
 *///from   w  w  w  . j a v  a 2s.  c o m
public boolean canLoanBook() {
    // Get the quantity of books stored
    Uri bookQuery = ContentUris.withAppendedId(PapyrusContentProvider.Books.CONTENT_URI, selectedBookID);
    String[] columns = { PapyrusContentProvider.Books.FIELD_QUANTITY };
    // store result of query
    Cursor result = resolver.query(bookQuery, columns, null, null, null);
    result.moveToFirst();
    int qty = result.getShort(0);

    String selection = PapyrusContentProvider.Loans.FIELD_BOOK_ID + " = ?";
    String[] selectionArgs = { Long.toString(selectedBookID) };
    columns[0] = PapyrusContentProvider.Loans.FIELD_ID;

    // store result of query
    result = resolver.query(PapyrusContentProvider.Loans.CONTENT_URI, columns, selection, selectionArgs, null);

    if (result.getCount() < qty) {
        result.close();
        return true;
    } else {
        result.close();
        return false;
    }
}

From source file:at.bitfire.davdroid.syncadapter.ContactsSyncManager.java

@Override
protected RequestBody prepareUpload(@NonNull LocalResource resource)
        throws IOException, ContactsStorageException {
    final Contact contact;
    if (resource instanceof LocalContact) {
        LocalContact local = ((LocalContact) resource);
        contact = local.getContact();/*from w  w w .  j av a2 s  .  c  o m*/

        if (groupMethod == GroupMethod.CATEGORIES) {
            // add groups as CATEGORIES
            for (long groupID : local.getGroupMemberships()) {
                try {
                    @Cleanup
                    Cursor c = provider.query(
                            localAddressBook()
                                    .syncAdapterURI(ContentUris.withAppendedId(Groups.CONTENT_URI, groupID)),
                            new String[] { Groups.TITLE }, null, null, null);
                    if (c != null && c.moveToNext()) {
                        String title = c.getString(0);
                        if (!TextUtils.isEmpty(title))
                            contact.categories.add(title);
                    }
                } catch (RemoteException e) {
                    throw new ContactsStorageException("Couldn't find group for adding CATEGORIES", e);
                }
            }
        }
    } else if (resource instanceof LocalGroup)
        contact = ((LocalGroup) resource).getContact();
    else
        throw new IllegalArgumentException("Argument must be LocalContact or LocalGroup");

    App.log.log(Level.FINE, "Preparing upload of VCard " + resource.getFileName(), contact);

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    contact.write(hasVCard4 ? VCardVersion.V4_0 : VCardVersion.V3_0, groupMethod, settings.getVCardRFC6868(),
            os);

    return RequestBody.create(hasVCard4 ? DavAddressBook.MIME_VCARD4 : DavAddressBook.MIME_VCARD3_UTF8,
            os.toByteArray());
}

From source file:org.mythtv.service.dvr.v25.RecordingRuleHelperV25.java

private void processRecordingRule(final Context context, final LocationProfile locationProfile,
        ArrayList<ContentProviderOperation> ops, org.mythtv.services.api.v025.beans.RecRule recRule) {
    Log.d(TAG, "processRecordingRule : enter");

    String recRuleSelection = RecordingRuleConstants.FIELD_REC_RULE_ID + " = ?";

    recRuleSelection = appendLocationHostname(context, locationProfile, recRuleSelection,
            RecordingRuleConstants.TABLE_NAME);

    ContentValues recRuleValues = convertRecRuleToContentValues(locationProfile, recRule);
    Cursor recRuleCursor = context.getContentResolver().query(RecordingRuleConstants.CONTENT_URI,
            recRuleProjection, recRuleSelection, new String[] { String.valueOf(recRule.getId()) }, null);
    if (recRuleCursor.moveToFirst()) {
        Long id = recRuleCursor.getLong(recRuleCursor.getColumnIndexOrThrow(RecordingRuleConstants._ID));
        Log.v(TAG, "processRecordingRule : updating recRule " + id + ":" + recRule.getId() + ":"
                + recRule.getTitle());//  ww w. ja  va2s.  c o m

        ops.add(ContentProviderOperation
                .newUpdate(ContentUris.withAppendedId(RecordingRuleConstants.CONTENT_URI, id))
                .withValues(recRuleValues).build());

    } else {
        Log.v(TAG, "processRecordingRule : adding recRule " + recRule.getId() + ":" + recRule.getTitle());

        ops.add(ContentProviderOperation.newInsert(RecordingRuleConstants.CONTENT_URI).withValues(recRuleValues)
                .build());

    }
    recRuleCursor.close();

    Log.d(TAG, "processRecordingRule : exit");
}

From source file:org.mythtv.service.dvr.v26.RecordingRuleHelperV26.java

private void processRecordingRule(final Context context, final LocationProfile locationProfile,
        ArrayList<ContentProviderOperation> ops, org.mythtv.services.api.v026.beans.RecRule recRule) {
    Log.d(TAG, "processRecordingRule : enter");

    String recRuleSelection = RecordingRuleConstants.FIELD_REC_RULE_ID + " = ?";

    recRuleSelection = appendLocationHostname(context, locationProfile, recRuleSelection,
            RecordingRuleConstants.TABLE_NAME);

    ContentValues recRuleValues = convertRecRuleToContentValues(locationProfile, recRule);
    Cursor recRuleCursor = context.getContentResolver().query(RecordingRuleConstants.CONTENT_URI,
            recRuleProjection, recRuleSelection, new String[] { String.valueOf(recRule.getId()) }, null);
    if (recRuleCursor.moveToFirst()) {
        Long id = recRuleCursor.getLong(recRuleCursor.getColumnIndexOrThrow(RecordingRuleConstants._ID));
        Log.v(TAG, "processRecordingRule : updating recRule " + id + ":" + recRule.getId() + ":"
                + recRule.getTitle());/*  ww w . j  a v a  2 s  . c o  m*/

        ops.add(ContentProviderOperation
                .newUpdate(ContentUris.withAppendedId(RecordingRuleConstants.CONTENT_URI, id))
                .withValues(recRuleValues).build());

    } else {
        Log.v(TAG, "processRecordingRule : adding recRule " + recRule.getId() + ":" + recRule.getTitle());

        ops.add(ContentProviderOperation.newInsert(RecordingRuleConstants.CONTENT_URI).withValues(recRuleValues)
                .build());

    }
    recRuleCursor.close();

    Log.d(TAG, "processRecordingRule : exit");
}

From source file:com.kyakujin.android.tagnotepad.ui.NoteListFragment.java

@Override
public boolean onContextItemSelected(android.view.MenuItem item) {

    AdapterView.AdapterContextMenuInfo info;
    try {/*from w  w w  .ja va2s.  c  om*/
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (ClassCastException e) {
        Log.e(TAG, "bad AdapterContextMenuInfo", e);
        return false;
    }

    mCurrentNote = ContentUris.withAppendedId(Notes.CONTENT_URI, info.id);
    switch (item.getItemId()) {
    case R.id.context_open:
        openNote(mCurrentNote);
        return true;
    case R.id.context_delete:
        // ?
        AlertDialog dlg = new AlertDialog.Builder(getActivity()).setTitle(R.string.alert_title_delete)
                .setIcon(android.R.drawable.ic_dialog_alert).setMessage(R.string.alert_message_delete_note)
                .setPositiveButton("YES", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        getActivity().getContentResolver().delete(mCurrentNote, null, null);
                    }
                }).setNegativeButton("NO", null).setInverseBackgroundForced(true).create();
        dlg.show();
        return true;
    case R.id.context_tag:
        Bundle bundle = new Bundle();
        bundle.putString(Config.SELECTED_NOTE_URI, mCurrentNote.toString());
        FragmentManager manager = getActivity().getSupportFragmentManager();
        TagDialogListFragment fragment = TagDialogListFragment.newInstance();
        fragment.setArguments(bundle);
        fragment.show(manager, Config.TAG_TAGDIALOGLIST_FRAGM);
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:org.mythtv.service.dvr.v27.RecordingRuleHelperV27.java

private void processRecordingRule(final Context context, final LocationProfile locationProfile,
        ArrayList<ContentProviderOperation> ops, org.mythtv.services.api.v027.beans.RecRule recRule) {
    Log.d(TAG, "processRecordingRule : enter");

    String recRuleSelection = RecordingRuleConstants.FIELD_REC_RULE_ID + " = ?";

    recRuleSelection = appendLocationHostname(context, locationProfile, recRuleSelection,
            RecordingRuleConstants.TABLE_NAME);

    ContentValues recRuleValues = convertRecRuleToContentValues(locationProfile, recRule);
    Cursor recRuleCursor = context.getContentResolver().query(RecordingRuleConstants.CONTENT_URI,
            recRuleProjection, recRuleSelection, new String[] { String.valueOf(recRule.getId()) }, null);
    if (recRuleCursor.moveToFirst()) {
        Long id = recRuleCursor.getLong(recRuleCursor.getColumnIndexOrThrow(RecordingRuleConstants._ID));
        Log.v(TAG, "processRecordingRule : updating recRule " + id + ":" + recRule.getId() + ":"
                + recRule.getTitle());//from  w  ww.  j  a  v  a  2s  .c  om

        ops.add(ContentProviderOperation
                .newUpdate(ContentUris.withAppendedId(RecordingRuleConstants.CONTENT_URI, id))
                .withValues(recRuleValues).build());

    } else {
        Log.v(TAG, "processRecordingRule : adding recRule " + recRule.getId() + ":" + recRule.getTitle());

        ops.add(ContentProviderOperation.newInsert(RecordingRuleConstants.CONTENT_URI).withValues(recRuleValues)
                .build());

    }
    recRuleCursor.close();

    Log.d(TAG, "processRecordingRule : exit");
}

From source file:com.sonetel.wizards.impl.Sonetel.java

public void SendMsgToNetWork(SipProfile account) {
    try {/*from w  ww.ja  va  2s  .c  om*/

        account = AccessNumbers.sendPostReq(account, "1", null, parent.getBaseContext(), null);

        int i = 0;
        if (account.pin == null) {
            //serviceHandler.sendMessage(serviceHandler.obtainMessage(TOAST_MESSAGE, 0, 0,"Unable to configure callthru. Please check your registration or contact Sonetel support"));
            //Toast.makeText(parent,"Unable to configure automated callthru. You may be need to enter your credentials", Toast.LENGTH_LONG).show();
            Log.e(THIS_FILE, "AccessNumbers.sendPostReq() failed. Callthru may not work");
            //return false;
        } else
            i = parent.getBaseContext().getContentResolver().update(
                    ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, account.id),
                    account.getDbContentValues(), null, null);

        //HTTPThread.stop();

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //return false;
}