Example usage for android.net Uri withAppendedPath

List of usage examples for android.net Uri withAppendedPath

Introduction

In this page you can find the example usage for android.net Uri withAppendedPath.

Prototype

public static Uri withAppendedPath(Uri baseUri, String pathSegment) 

Source Link

Document

Creates a new Uri by appending an already-encoded path segment to a base Uri.

Usage

From source file:org.openintents.shopping.ui.ShoppingActivity.java

/**
 * Edit item/* ww  w.j  a  va  2 s .c  o  m*/
 *
 * @param field
 */
void editItem(long itemId, long containsId, EditItemDialog.FieldType field) {
    mItemUri = Uri.withAppendedPath(ShoppingContract.Items.CONTENT_URI, "" + itemId);
    mListItemUri = Uri.withAppendedPath(mListUri, "" + itemId);
    mRelationUri = Uri.withAppendedPath(ShoppingContract.Contains.CONTENT_URI, "" + containsId);
    mEditItemFocusField = field;

    showDialog(DIALOG_EDIT_ITEM);
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

/**
 * move item//from  w ww  .  ja  va 2 s  . co  m
 */
void moveItem(int position, int targetListId) {
    Cursor c = mItemsView.mCursorItems;
    mItemsView.mCursorItems.requery();
    c.moveToPosition(position);

    long listId = getSelectedListId();
    if (false && listId < 0) {
        // No valid list - probably view is not active
        // and no item is selected.
        return;
    }
    listId = Integer.parseInt(mListUri.getLastPathSegment());

    // Attach item to new list, preserving all other fields
    String containsId = c.getString(mStringItemsCONTAINSID);
    ContentValues cv = new ContentValues(1);
    cv.put(Contains.LIST_ID, targetListId);
    getContentResolver().update(Uri.withAppendedPath(Contains.CONTENT_URI, containsId), cv, null, null);

    mItemsView.requery();
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

/**
 * copy item//www  .  j  av a 2s.c  o m
 */
void copyItem(int position) {
    Cursor c = mItemsView.mCursorItems;
    mItemsView.mCursorItems.requery();
    c.moveToPosition(position);
    String containsId = c.getString(mStringItemsCONTAINSID);
    Long newContainsId;
    Long newItemId;

    c = getContentResolver().query(
            Uri.withAppendedPath(Uri.withAppendedPath(Contains.CONTENT_URI, "copyof"), containsId),
            new String[] { "item_id", "contains_id" }, null, null, null);

    if (c.getCount() != 1) {
        return;
    }

    c.moveToFirst();
    newItemId = c.getLong(0);
    newContainsId = c.getLong(1);
    c.deactivate();
    c.close();

    editItem(newItemId, newContainsId, FieldType.ITEMNAME);

    // mItemsView.requery();
}

From source file:org.apache.cordova.ContactAccessorSdk5.java

@Override
/**//from w w  w.  ja  v a  2 s .  c o  m
 * This method will remove a Contact from the database based on ID.
 * @param id the unique ID of the contact to remove
 */
public boolean remove(String id) {
    int result = 0;
    Cursor cursor = mApp.getActivity().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null,
            ContactsContract.Contacts._ID + " = ?", new String[] { id }, null);
    if (cursor.getCount() == 1) {
        cursor.moveToFirst();
        String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
        Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
        result = mApp.getActivity().getContentResolver().delete(uri, null, null);
    } else {
        Log.d(LOG_TAG, "Could not find contact with ID");
    }

    return (result > 0) ? true : false;
}

From source file:com.remobile.contacts.ContactAccessorSdk5.java

@Override
/**/*from w  w w . j  ava  2s. c  o m*/
 * This method will remove a Contact from the database based on ID.
 * @param id the unique ID of the contact to remove
 */
public boolean remove(String id) {
    int result = 0;
    Cursor cursor = mApp.getActivity().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null,
            ContactsContract.Contacts._ID + " = ?", new String[] { id }, null);
    if (cursor.getCount() == 1) {
        cursor.moveToFirst();
        String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
        Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
        result = mApp.getActivity().getContentResolver().delete(uri, null, null);
    } else {
        Log.d(LOG_TAG, "Could not find contact with ID");
    }

    cursor.close();

    return (result > 0) ? true : false;
}

From source file:com.android.calendar.EventInfoFragment.java

/**
 * Taken from com.google.android.gm.HtmlConversationActivity
 *
 * Send the intent that shows the Contact info corresponding to the email address.
 *///  w  w  w  .j ava  2  s.co  m
public void showContactInfo(Attendee attendee, Rect rect) {
    // First perform lookup query to find existing contact
    final ContentResolver resolver = getActivity().getContentResolver();
    final String address = attendee.mEmail;
    final Uri dataUri = Uri.withAppendedPath(CommonDataKinds.Email.CONTENT_FILTER_URI, Uri.encode(address));
    final Uri lookupUri = ContactsContract.Data.getContactLookupUri(resolver, dataUri);

    if (lookupUri != null) {
        // Found matching contact, trigger QuickContact
        QuickContact.showQuickContact(getActivity(), rect, lookupUri, QuickContact.MODE_MEDIUM, null);
    } else {
        // No matching contact, ask user to create one
        final Uri mailUri = Uri.fromParts("mailto", address, null);
        final Intent intent = new Intent(Intents.SHOW_OR_CREATE_CONTACT, mailUri);

        // Pass along full E-mail string for possible create dialog
        Rfc822Token sender = new Rfc822Token(attendee.mName, attendee.mEmail, null);
        intent.putExtra(Intents.EXTRA_CREATE_DESCRIPTION, sender.toString());

        // Only provide personal name hint if we have one
        final String senderPersonal = attendee.mName;
        if (!TextUtils.isEmpty(senderPersonal)) {
            intent.putExtra(Intents.Insert.NAME, senderPersonal);
        }

        startActivity(intent);
    }
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

/**
 * Returns the ID of the selected shopping list.
 * <p/>//from w w w  .  ja v a  2s  . co m
 * As a side effect, the item URI is updated. Returns -1 if nothing is
 * selected.
 *
 * @return ID of selected shopping list.
 */
private long getSelectedListId() {
    int pos = mShoppingListsView.getSelectedItemPosition();
    // Temp- Due to architecture requirements of OS 3, the value can not be
    // passed directly
    if (pos == -1 && !usingListSpinner()) {
        try {
            pos = (Integer) mShoppingListsView.getTag();
            pos = mCursorShoppingLists.getCount() <= pos ? -1 : pos;
        } catch (Exception e) {
            // e.printStackTrace();
        }
    }
    if (pos < 0) {
        // nothing selected - probably view is out of focus:
        // Do nothing.
        return -1;
    }

    // Obtain Id of currently selected shopping list:
    mCursorShoppingLists.moveToPosition(pos);

    long listId = mCursorShoppingLists.getLong(mStringListFilterID);

    mListUri = Uri.withAppendedPath(ShoppingContract.Lists.CONTENT_URI, "" + listId);

    getIntent().setData(mListUri);

    return listId;
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

public void saveListTheme(String theme) {
    long listId = getSelectedListId();
    if (listId < 0) {
        // No valid list - probably view is not active
        // and no item is selected.
        return; // return default theme
    }//from  ww  w .j av  a 2 s  . c om

    ContentValues values = new ContentValues();
    values.put(Lists.SKIN_BACKGROUND, theme);
    getContentResolver().update(Uri.withAppendedPath(Lists.CONTENT_URI, mCursorShoppingLists.getString(0)),
            values, null, null);

    mCursorShoppingLists.requery();
}

From source file:com.android.bluetooth.map.BluetoothMapContent.java

private void setVCardFromPhoneNumber(BluetoothMapbMessage message, String phone, boolean incoming) {
    if (TextUtils.isEmpty(phone)) {
        return;/*from   w w w  .j a v a  2 s  . c  om*/
    }
    String contactId = null, contactName = null;
    String[] phoneNumbers = null;
    String[] emailAddresses = null;

    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone));

    String[] projection = { Contacts._ID, Contacts.DISPLAY_NAME };
    String selection = Contacts.IN_VISIBLE_GROUP + "=1";
    String orderBy = Contacts._ID + " ASC";

    // Get the contact _ID and name
    Cursor p = mResolver.query(uri, projection, selection, null, orderBy);

    try {
        if (p != null && p.getCount() >= 1) {
            p.moveToFirst();
            contactId = p.getString(p.getColumnIndex(Contacts._ID));
            contactName = p.getString(p.getColumnIndex(Contacts.DISPLAY_NAME));
        }

        // Bail out if we are unable to find a contact, based on the phone number
        if (contactId == null) {
            phoneNumbers = new String[1];
            phoneNumbers[0] = phone;
        } else {
            // use only actual phone number
            phoneNumbers = new String[1];
            phoneNumbers[0] = phone;

            // Fetch contact e-mail addresses
            close(p);
            p = mResolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { contactId },
                    null);
            if (p != null) {
                int i = 0;
                emailAddresses = new String[p.getCount()];
                while (p != null && p.moveToNext()) {
                    String emailAddress = p
                            .getString(p.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS));
                    emailAddresses[i++] = emailAddress;
                }
            }
        }
    } finally {
        close(p);
    }
    if (incoming == true)
        message.addOriginator(contactName, contactName, phoneNumbers, emailAddresses); // Use version 3.0 as we only have a formatted name
    else
        message.addRecipient(contactName, contactName, phoneNumbers, emailAddresses); // Use version 3.0 as we only have a formatted name
}

From source file:org.odk.collect.android.activities.FormEntryActivity.java

/**
 * Returns the instance that was just filled out to the calling activity, if
 * requested./*from   www. jav a2 s . c om*/
 */
private void finishReturnInstance() {
    FormController formController = Collect.getInstance().getFormController();
    String action = getIntent().getAction();
    if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_EDIT.equals(action)) {
        // caller is waiting on a picked form
        Cursor c = null;
        try {
            c = new InstancesDao()
                    .getInstancesCursorForFilePath(formController.getInstancePath().getAbsolutePath());
            if (c.getCount() > 0) {
                // should only be one...
                c.moveToFirst();
                String id = c.getString(c.getColumnIndex(InstanceColumns._ID));
                Uri instance = Uri.withAppendedPath(InstanceColumns.CONTENT_URI, id);
                setResult(RESULT_OK, new Intent().setData(instance));
            }
        } finally {
            if (c != null) {
                c.close();
            }
        }
    }
    finish();
}