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

private boolean QuickEditFieldPopupMenu(final Cursor c, final int pos, final FieldType field, View v) {
    QuickSelectMenu popup = new QuickSelectMenu(this, v);

    Menu menu = popup.getMenu();/*from   w ww . ja  v  a2  s .  com*/
    if (menu == null) {
        return false;
    }
    menu.add("1");
    menu.add("2");
    menu.add("3");
    menu.add("4");
    menu.add("5");
    if (field == FieldType.QUANTITY) {
        menu.add(R.string.otherqty);
    }
    if (field == FieldType.PRIORITY) {
        menu.add(R.string.otherpri);
    }

    popup.setOnItemSelectedListener(new QuickSelectMenu.OnItemSelectedListener() {
        public void onItemSelected(CharSequence name, int id) {
            // TODO: use a flavor of menu.add which takes id,
            // then identifying the selection becomes easier here.

            if (name.length() > 1) {
                // Other ... use edit dialog
                editItem(pos, field);
            } else {
                long number = name.charAt(0) - '0';
                ContentValues values = new ContentValues();
                switch (field) {
                case PRIORITY:
                    values.put(Contains.PRIORITY, number);
                    break;
                case QUANTITY:
                    values.put(Contains.QUANTITY, number);
                    break;
                }
                mItemsView.mCursorItems.moveToPosition(pos);
                String containsId = mItemsView.mCursorItems.getString(mStringItemsCONTAINSID);
                Uri uri = Uri.withAppendedPath(ShoppingContract.Contains.CONTENT_URI, containsId);
                getApplicationContext().getContentResolver().update(uri, values, null, null);
                onItemChanged(); // probably overkill
                mItemsView.updateTotal();
            }
        }
    });

    popup.show();
    return true;
}

From source file:com.fvd.nimbus.PaintActivity.java

private String getImagePath() {

    String[] projection = { MediaStore.Images.Thumbnails._ID, // The columns we want
            MediaStore.Images.Thumbnails.IMAGE_ID, MediaStore.Images.Thumbnails.KIND,
            MediaStore.Images.Thumbnails.DATA };
    String selection = MediaStore.Images.Thumbnails.KIND + "=" + // Select only mini's
            MediaStore.Images.Thumbnails.MINI_KIND;

    String sort = MediaStore.Images.Thumbnails._ID + " DESC";

    //At the moment, this is a bit of a hack, as I'm returning ALL images, and just taking the latest one. There is a better way to narrow this down I think with a WHERE clause which is currently the selection variable
    Cursor myCursor = this.managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection,
            selection, null, sort);/*w  w w  . j  a v a  2 s  . c o m*/

    long imageId = 0l;
    long thumbnailImageId = 0l;
    String thumbnailPath = "";

    try {
        myCursor.moveToFirst();
        imageId = myCursor.getLong(myCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.IMAGE_ID));
        thumbnailImageId = myCursor.getLong(myCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID));
        thumbnailPath = myCursor.getString(myCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA));
    } finally {
        myCursor.close();
    }

    //Create new Cursor to obtain the file Path for the large image

    String[] largeFileProjection = { MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA };

    String largeFileSort = MediaStore.Images.ImageColumns._ID + " DESC";
    myCursor = this.managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, largeFileProjection, null, null,
            largeFileSort);
    String largeImagePath = "";

    try {
        myCursor.moveToFirst();

        largeImagePath = myCursor
                .getString(myCursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.DATA));
    } finally {
        myCursor.close();
    }
    // These are the two URI's you'll be interested in. They give you a handle to the actual images
    Uri uriLargeImage = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            String.valueOf(imageId));
    Uri uriThumbnailImage = Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
            String.valueOf(thumbnailImageId));

    if (largeImagePath.length() > 0)
        return largeImagePath;
    else if (uriLargeImage != null)
        return uriLargeImage.getPath();
    else if (uriThumbnailImage != null)
        return uriThumbnailImage.getPath();
    else
        return "";

}

From source file:com.android.contacts.ContactSaveService.java

private void joinContacts(Intent intent) {
    long contactId1 = intent.getLongExtra(EXTRA_CONTACT_ID1, -1);
    long contactId2 = intent.getLongExtra(EXTRA_CONTACT_ID2, -1);

    // Load raw contact IDs for all raw contacts involved - currently edited and selected
    // in the join UIs.
    long rawContactIds[] = getRawContactIdsForAggregation(contactId1, contactId2);
    if (rawContactIds == null) {
        Log.e(TAG, "Invalid arguments for joinContacts request");
        return;/*from  ww w.j  av a 2  s.co  m*/
    }

    ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();

    // For each pair of raw contacts, insert an aggregation exception
    for (int i = 0; i < rawContactIds.length; i++) {
        for (int j = 0; j < rawContactIds.length; j++) {
            if (i != j) {
                buildJoinContactDiff(operations, rawContactIds[i], rawContactIds[j]);
            }
        }
    }

    final ContentResolver resolver = getContentResolver();

    // Use the name for contactId1 as the name for the newly aggregated contact.
    final Uri contactId1Uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId1);
    final Uri entityUri = Uri.withAppendedPath(contactId1Uri, Contacts.Entity.CONTENT_DIRECTORY);
    Cursor c = resolver.query(entityUri, ContactEntityQuery.PROJECTION, ContactEntityQuery.SELECTION, null,
            null);
    if (c == null) {
        Log.e(TAG, "Unable to open Contacts DB cursor");
        showToast(R.string.contactSavedErrorToast);
        return;
    }
    long dataIdToAddSuperPrimary = -1;
    try {
        if (c.moveToFirst()) {
            dataIdToAddSuperPrimary = c.getLong(ContactEntityQuery.DATA_ID);
        }
    } finally {
        c.close();
    }

    // Mark the name from contactId1 IS_SUPER_PRIMARY to make sure that the contact
    // display name does not change as a result of the join.
    if (dataIdToAddSuperPrimary != -1) {
        Builder builder = ContentProviderOperation
                .newUpdate(ContentUris.withAppendedId(Data.CONTENT_URI, dataIdToAddSuperPrimary));
        builder.withValue(Data.IS_SUPER_PRIMARY, 1);
        builder.withValue(Data.IS_PRIMARY, 1);
        operations.add(builder.build());
    }

    // Apply all aggregation exceptions as one batch
    final boolean success = applyOperations(resolver, operations);

    final String name = queryNameOfLinkedContacts(new long[] { contactId1, contactId2 });
    Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT);
    if (success && name != null) {
        if (TextUtils.isEmpty(name)) {
            showToast(R.string.contactsJoinedMessage);
        } else {
            showToast(R.string.contactsJoinedNamedMessage, name);
        }
        Uri uri = RawContacts.getContactLookupUri(resolver,
                ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactIds[0]));
        callbackIntent.setData(uri);
        LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(BROADCAST_LINK_COMPLETE));
    }
    deliverCallback(callbackIntent);
}

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

/**
 * Creates an exception to a recurring event.  The only change we're making is to the
 * "self attendee status" value.  The provider will take care of updating the corresponding
 * Attendees.attendeeStatus entry./*  ww w  .ja  v a2 s . c  o  m*/
 *
 * @param eventId The recurring event.
 * @param status The new value for selfAttendeeStatus.
 */
private void createExceptionResponse(long eventId, int status) {
    ContentValues values = new ContentValues();
    values.put(Events.ORIGINAL_INSTANCE_TIME, mStartMillis);
    values.put(Events.SELF_ATTENDEE_STATUS, status);
    values.put(Events.STATUS, Events.STATUS_CONFIRMED);

    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
    Uri exceptionUri = Uri.withAppendedPath(Events.CONTENT_EXCEPTION_URI, String.valueOf(eventId));
    ops.add(ContentProviderOperation.newInsert(exceptionUri).withValues(values).build());

    mHandler.startBatch(mHandler.getNextToken(), null, CalendarContract.AUTHORITY, ops, Utils.UNDO_DELAY);
}

From source file:com.android.mms.transaction.MessagingNotification.java

/**
 * Return the pending intent for failed messages in folder mode.
 * @param context The context//from  ww w .jav a 2 s .  com
 * @param failedCount The failed messages' count
 * @param isDownload Whether the messages is for received
 */
private static Intent getFailedIntentFromFolderMode(Context context, int failedCount, boolean isDownload) {
    // Query the DB and return the cursor of the  undelivered messages
    Cursor cursor = SqliteWrapper.query(context, context.getContentResolver(), UNDELIVERED_URI,
            MAILBOX_PROJECTION, "read=0", null, null);
    if (cursor == null) {
        return null;
    }

    try {
        int mailboxId = MailBoxMessageList.TYPE_INVALID;
        Intent failedIntent;

        if (failedCount > 1) {
            if (isFailedMessagesInSameBox(cursor)) {
                mailboxId = getUndeliveredMessageBoxId(cursor);
            } else {
                mailboxId = MailBoxMessageList.TYPE_INBOX;
            }

            failedIntent = new Intent(context, MailBoxMessageList.class);
            failedIntent.putExtra(MessageUtils.MAIL_BOX_ID, mailboxId);
            failedIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            return failedIntent;
        }

        // The rest cases: the "failedCount" is 1.
        Uri msgUri;
        String type = getUndeliveredMessageType(cursor);
        Long msgId = getUndeliveredMessageId(cursor);
        if (TextUtils.isEmpty(type)) {
            return null;
        }
        if (type.equals("sms")) {
            failedIntent = new Intent(context, MailBoxMessageContent.class);
            msgUri = Uri.withAppendedPath(Sms.CONTENT_URI, String.valueOf(msgId));
            failedIntent.setData(msgUri);
        } else {
            // MMS type.
            if (isDownload) {
                //  Download fail will jump to MailBoxMessageList INBOX.
                failedIntent = new Intent(context, MailBoxMessageList.class);
                mailboxId = MailBoxMessageList.TYPE_INBOX;
                failedIntent.putExtra(MessageUtils.MAIL_BOX_ID, mailboxId);
            } else {
                failedIntent = new Intent(context, MobilePaperShowActivity.class);
                msgUri = Uri.withAppendedPath(Mms.CONTENT_URI, String.valueOf(msgId));
                failedIntent.setData(msgUri);
            }
        }
        failedIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        return failedIntent;
    } finally {
        cursor.close();
    }
}

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

/**
 * Rename list from dialog.//from   www . ja  v a 2  s .  com
 *
 * @return true if new list was renamed. False if new list was not renamed,
 * because user has not given any name.
 */
private boolean renameList(String newName) {

    if (newName.equals("")) {
        // User has not provided any name
        Toast.makeText(this, getString(R.string.please_enter_name), Toast.LENGTH_SHORT).show();
        return false;
    }

    // Rename currently selected list:
    ContentValues values = new ContentValues();
    values.put(Lists.NAME, "" + newName);
    getContentResolver().update(Uri.withAppendedPath(Lists.CONTENT_URI, mCursorShoppingLists.getString(0)),
            values, null, null);

    mCursorShoppingLists.requery();
    updateTitle();
    return true;
}

From source file:org.skt.runtime.html5apis.contacts.ContactAccessorSdk5.java

@Override
/** //from  www  . j a  v  a 2 s .  c om
 * 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.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.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.xandy.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  .  com
public void showContactInfo(CalendarEventModel.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:com.karura.framework.plugins.utils.ContactAccessorSdk5.java

@Override
/**//from  ww w  .ja va 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 = getContext().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 = getContext().getContentResolver().delete(uri, null, null);
    } else {
        Log.d(LOG_TAG, "Could not find contact with ID");
    }

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